Skip to content

Commit a0db0da

Browse files
authored
Python generator: use Mapping instead of Dict for type annotations (#415)
Fixes #414
1 parent a79f4dc commit a0db0da

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

generator/plugins/python/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _reset(self):
208208
self._imports: List[str] = [
209209
"import enum",
210210
"import functools",
211-
"from typing import Any, Dict, Literal, Optional, Sequence, Tuple, Union",
211+
"from typing import Any, Dict, Mapping, Literal, Optional, Sequence, Tuple, Union",
212212
"import attrs",
213213
"from . import validators",
214214
]
@@ -356,7 +356,7 @@ def _generate_type_name(
356356

357357
if type_def.kind == "map":
358358
# This kind defines a dictionary like object.
359-
return f"Dict[{self._generate_type_name(type_def.key, class_name, prefix)}, {self._generate_type_name(type_def.value, class_name, prefix)}]"
359+
return f"Mapping[{self._generate_type_name(type_def.key, class_name, prefix)}, {self._generate_type_name(type_def.value, class_name, prefix)}]"
360360

361361
if type_def.kind == "tuple":
362362
# This kind defined a tuple like object.

packages/python/lsprotocol/types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import enum
1111
import functools
12-
from typing import Any, Dict, Literal, Optional, Sequence, Tuple, Union
12+
from typing import Any, Dict, Mapping, Literal, Optional, Sequence, Tuple, Union
1313
import attrs
1414
from . import validators
1515

@@ -1955,7 +1955,7 @@ class WorkspaceEdit:
19551955
cause failure of the operation. How the client recovers from the failure is described by
19561956
the client capability: `workspace.workspaceEdit.failureHandling`"""
19571957

1958-
changes: Optional[Dict[str, Sequence["TextEdit"]]] = attrs.field(default=None)
1958+
changes: Optional[Mapping[str, Sequence["TextEdit"]]] = attrs.field(default=None)
19591959
"""Holds changes to existing resources."""
19601960

19611961
document_changes: Optional[
@@ -1973,7 +1973,7 @@ class WorkspaceEdit:
19731973
only plain `TextEdit`s using the `changes` property are supported."""
19741974

19751975
change_annotations: Optional[
1976-
Dict[ChangeAnnotationIdentifier, "ChangeAnnotation"]
1976+
Mapping[ChangeAnnotationIdentifier, "ChangeAnnotation"]
19771977
] = attrs.field(default=None)
19781978
"""A map of change annotations that can be referenced in `AnnotatedTextEdit`s or create, rename and
19791979
delete file / folder operations.
@@ -2452,7 +2452,7 @@ class DocumentDiagnosticReportPartialResult:
24522452

24532453
# Since: 3.17.0
24542454

2455-
related_documents: Dict[
2455+
related_documents: Mapping[
24562456
str, Union["FullDocumentDiagnosticReport", "UnchangedDocumentDiagnosticReport"]
24572457
] = attrs.field()
24582458

@@ -5642,7 +5642,7 @@ class RelatedFullDocumentDiagnosticReport:
56425642
"""The actual items."""
56435643

56445644
related_documents: Optional[
5645-
Dict[
5645+
Mapping[
56465646
str,
56475647
Union[FullDocumentDiagnosticReport, "UnchangedDocumentDiagnosticReport"],
56485648
]
@@ -5703,7 +5703,7 @@ class RelatedUnchangedDocumentDiagnosticReport:
57035703
diagnostic request for the same document."""
57045704

57055705
related_documents: Optional[
5706-
Dict[
5706+
Mapping[
57075707
str, Union[FullDocumentDiagnosticReport, UnchangedDocumentDiagnosticReport]
57085708
]
57095709
] = attrs.field(default=None)

0 commit comments

Comments
 (0)