Skip to content

Commit cea73e5

Browse files
authored
Merge ec0deec into 816496f
2 parents 816496f + ec0deec commit cea73e5

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

source/NVDAObjects/IAccessible/ia2Web.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"""
88
import typing
99
from typing import (
10-
Iterable,
10+
Generator,
11+
Optional,
1112
)
1213
from ctypes import c_short
1314
from comtypes import COMError, BSTR
@@ -57,7 +58,7 @@ def __bool__(self) -> bool:
5758
)
5859

5960
@property
60-
def targets(self) -> Iterable[AnnotationTarget]:
61+
def targets(self) -> Generator[AnnotationTarget, None, None]:
6162
if not bool(self):
6263
# optimisation that avoids having to fetch details relations which may be a more costly procedure.
6364
if config.conf["debugLog"]["annotations"]:
@@ -71,7 +72,7 @@ def targets(self) -> Iterable[AnnotationTarget]:
7172
yield from ia2WebAnnotationTargetsGen
7273

7374
@property
74-
def roles(self) -> Iterable[controlTypes.Role]:
75+
def roles(self) -> Generator[Optional[controlTypes.Role], None, None]:
7576
"""
7677
Since Chromium exposes the roles via the "details-roles" IA2Attributes, an optimisation can be used
7778
to return them.
@@ -96,7 +97,7 @@ def roles(self) -> Iterable[controlTypes.Role]:
9697
yield detailsRole
9798

9899
@property
99-
def summaries(self) -> Iterable[str]:
100+
def summaries(self) -> Generator[str, None, None]:
100101
for target in self.targets:
101102
yield target.summary
102103

source/NVDAObjects/IAccessible/mozilla.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Copyright (C) 2006-2022 NV Access Limited, Peter Vágner
66

77
from typing import (
8-
Iterable,
8+
Generator,
99
Optional,
1010
)
1111

@@ -34,7 +34,7 @@ def summary(self) -> str:
3434
return self._target.summarizeInProcess()
3535

3636
@property
37-
def role(self) -> controlTypes.Role:
37+
def role(self) -> Optional[controlTypes.Role]:
3838
# details-roles is currently only defined in Chromium
3939
# this may diverge in Firefox in the future.
4040
from .chromium import supportedAriaDetailsRoles
@@ -46,7 +46,10 @@ def role(self) -> controlTypes.Role:
4646
log.debug(f"detailsRole: {repr(detailsRole)}")
4747
if detailsRole in supportedAriaDetailsRoles.values():
4848
return detailsRole
49-
raise ValueError(f"Unsupported aria details role: {detailsRole}")
49+
50+
if config.conf["debugLog"]["annotations"]:
51+
log.warning(f"Unsupported aria details role: {detailsRole}")
52+
return None
5053

5154
@property
5255
def targetObject(self) -> IAccessible:
@@ -68,25 +71,24 @@ def __bool__(self) -> bool:
6871
)
6972

7073
@property
71-
def targets(self) -> Iterable[MozAnnotationTarget]:
74+
def targets(self) -> Generator[MozAnnotationTarget, None, None]:
7275
detailsRelations = self._originObj.detailsRelations
7376
for rel in detailsRelations:
7477
yield MozAnnotationTarget(rel)
7578

7679
@property
77-
def roles(self) -> Iterable[controlTypes.Role]:
80+
def roles(self) -> Generator[Optional[controlTypes.Role], None, None]:
7881
# Unlike base Ia2Web implementation, the details-roles
7982
# IA2 attribute is not exposed in Firefox.
8083
# Although slower, we have to fetch the details relations instead.
8184
for target in self.targets:
82-
# just take the first target for now.
8385
try:
8486
yield target.role
8587
except ValueError:
8688
log.error("Error getting role.", exc_info=True)
8789

8890
@property
89-
def summaries(self) -> Iterable[str]:
91+
def summaries(self) -> Generator[str, None, None]:
9092
for target in self.targets:
9193
yield target.summary
9294

source/annotation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from dataclasses import dataclass
1414
from typing import (
1515
TYPE_CHECKING,
16-
Iterable,
16+
Generator,
1717
List,
1818
Optional,
1919
Set,
@@ -35,7 +35,7 @@ class AnnotationTarget:
3535
"""
3636

3737
@property
38-
def role(self) -> "controlTypes.Role":
38+
def role(self) -> Optional["controlTypes.Role"]:
3939
raise NotImplementedError
4040

4141
@property
@@ -65,15 +65,15 @@ def __bool__(self):
6565
raise NotImplementedError
6666

6767
@property
68-
def targets(self) -> Iterable[AnnotationTarget]:
68+
def targets(self) -> Generator[AnnotationTarget, None, None]:
6969
raise NotImplementedError
7070

7171
@property
72-
def roles(self) -> Iterable["controlTypes.Role"]:
72+
def roles(self) -> Generator[Optional["controlTypes.Role"], None, None]:
7373
raise NotImplementedError
7474

7575
@property
76-
def summaries(self) -> Iterable[str]:
76+
def summaries(self) -> Generator[str, None, None]:
7777
raise NotImplementedError
7878

7979

0 commit comments

Comments
 (0)