Skip to content

Commit c63897f

Browse files
committed
Resolve mypy error with temporary fix.
See #402 for the issue to make a proper fix.
1 parent 079a887 commit c63897f

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

delphin/dmrs/_operations.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"""
55

66
import warnings
7-
from typing import Callable, Dict, List, Optional, cast
7+
from typing import Callable, Optional, cast
88

99
from delphin import dmrs, mrs, scope, variable
1010

11-
_HCMap = Dict[str, mrs.HCons]
12-
_IdMap = Dict[str, int]
11+
_HCMap = dict[str, mrs.HCons]
12+
_IdMap = dict[str, int]
1313

1414

1515
def from_mrs(
@@ -32,7 +32,11 @@ def from_mrs(
3232
DMRSError when conversion fails.
3333
"""
3434
hcmap: _HCMap = {hc.hi: hc for hc in m.hcons}
35-
reps = scope.representatives(m, priority=representative_priority)
35+
# TODO: fix type annotation with scope.representatives overloads?
36+
reps = cast(
37+
dict[str, list[mrs.EP]],
38+
scope.representatives(m, priority=representative_priority)
39+
)
3640
# EP id to node id map; create now to keep ids consistent
3741
id_to_nid: _IdMap = {ep.id: i
3842
for i, ep in enumerate(m.rels, dmrs.FIRST_NODE_ID)}
@@ -83,7 +87,7 @@ def _mrs_get_top(
8387
return top
8488

8589

86-
def _mrs_to_nodes(m: mrs.MRS, id_to_nid: _IdMap) -> List[dmrs.Node]:
90+
def _mrs_to_nodes(m: mrs.MRS, id_to_nid: _IdMap) -> list[dmrs.Node]:
8791
nodes = []
8892
for ep in m.rels:
8993
node_id = id_to_nid[ep.id]
@@ -117,10 +121,10 @@ def _mrs_to_nodes(m: mrs.MRS, id_to_nid: _IdMap) -> List[dmrs.Node]:
117121
def _mrs_to_links(
118122
m: mrs.MRS,
119123
hcmap: _HCMap,
120-
reps: scope.ScopeMap,
124+
reps: dict[str, list[mrs.EP]], # MRS-specific ScopeMap
121125
iv_to_nid: _IdMap,
122126
id_to_nid: _IdMap
123-
) -> List[dmrs.Link]:
127+
) -> list[dmrs.Link]:
124128
links = []
125129
# links from arguments
126130
for src, roleargs in m.arguments().items():

delphin/scope.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Structures and operations for quantifier scope in DELPH-IN semantics.
33
"""
44

5-
from typing import Dict, Iterable, List, Mapping, Optional, Tuple
5+
from typing import Iterable, Mapping, Optional
66

77
# Default modules need to import the PyDelphin version
88
from delphin.__about__ import __version__ # noqa: F401
@@ -29,11 +29,11 @@
2929
ScopeLabel = str
3030
ScopeRelation = str
3131
ScopeMap = Mapping[ScopeLabel, Predications]
32-
DescendantMap = Mapping[Identifier, List[Predication]]
33-
ScopalRoleArgument = Tuple[Role, ScopeRelation, Identifier]
34-
ScopalArgumentStructure = Mapping[Identifier, List[ScopalRoleArgument]]
32+
DescendantMap = Mapping[Identifier, list[Predication]]
33+
ScopalRoleArgument = tuple[Role, ScopeRelation, Identifier]
34+
ScopalArgumentStructure = Mapping[Identifier, list[ScopalRoleArgument]]
3535
# Regarding literal types, see: https://www.python.org/dev/peps/pep-0563/
36-
ScopeEqualities = Iterable[Tuple[ScopeLabel, ScopeLabel]]
36+
ScopeEqualities = Iterable[tuple[ScopeLabel, ScopeLabel]]
3737

3838

3939
# Exceptions
@@ -87,7 +87,7 @@ def scopal_arguments(self, scopes=None) -> ScopalArgumentStructure:
8787
"""
8888
raise NotImplementedError()
8989

90-
def scopes(self) -> Tuple[ScopeLabel, ScopeMap]:
90+
def scopes(self) -> tuple[ScopeLabel, ScopeMap]:
9191
"""
9292
Return a tuple containing the top label and the scope map.
9393
@@ -117,7 +117,7 @@ def conjoin(scopes: ScopeMap, leqs: ScopeEqualities) -> ScopeMap:
117117
>>> {lbl: [p.id for p in ps] for lbl, ps in conjoined.items()}
118118
{'h1': ['e2'], 'h2': ['x4', 'e6']}
119119
"""
120-
scopemap: Dict[ScopeLabel, List[Predication]] = {}
120+
scopemap: dict[ScopeLabel, list[Predication]] = {}
121121
for component in _connected_components(list(scopes), leqs):
122122
chosen_label = next(iter(component))
123123
scopemap[chosen_label] = []
@@ -155,13 +155,13 @@ def descendants(x: ScopingSemanticStructure,
155155
if scopes is None:
156156
_, scopes = x.scopes()
157157
scargs = x.scopal_arguments(scopes=scopes)
158-
descs: Dict[Identifier, List[Predication]] = {}
158+
descs: dict[Identifier, list[Predication]] = {}
159159
for p in x.predications:
160160
_descendants(descs, p.id, scargs, scopes)
161161
return descs
162162

163163

164-
def _descendants(descs: Dict[Identifier, List[Predication]],
164+
def _descendants(descs: dict[Identifier, list[Predication]],
165165
id: Identifier,
166166
scargs: ScopalArgumentStructure,
167167
scopes: ScopeMap) -> None:
@@ -203,7 +203,7 @@ def representatives(x: ScopingSemanticStructure, priority=None) -> ScopeMap:
203203
204204
3. Prefer tensed over untensed eventualities
205205
206-
4. Finally, prefer prefer those appearing first in *x*
206+
4. Finally, prefer those appearing first in *x*
207207
208208
The definition of "tensed" vs "untensed" eventualities is
209209
grammar-specific, but it is used by several large grammars. If a
@@ -233,7 +233,7 @@ def representatives(x: ScopingSemanticStructure, priority=None) -> ScopeMap:
233233
descs = {id: set(d.id for d in ds)
234234
for id, ds in descendants(x, scopes).items()}
235235

236-
reps: Dict[ScopeLabel, List[Predication]] = {
236+
reps: dict[ScopeLabel, list[Predication]] = {
237237
label: [] for label in scopes
238238
}
239239
for label, scope in scopes.items():

0 commit comments

Comments
 (0)