Skip to content

Commit 6346a2a

Browse files
committed
Python generator: use Mapping instead of Dict for type annotations
Fixes #414
1 parent 4dd0484 commit 6346a2a

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

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

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

19631963
document_changes: Optional[
@@ -1975,7 +1975,7 @@ class WorkspaceEdit:
19751975
only plain `TextEdit`s using the `changes` property are supported."""
19761976

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

24552455
# Since: 3.17.0
24562456

2457-
related_documents: Dict[
2457+
related_documents: Mapping[
24582458
str, Union["FullDocumentDiagnosticReport", "UnchangedDocumentDiagnosticReport"]
24592459
] = attrs.field()
24602460

@@ -5644,7 +5644,7 @@ class RelatedFullDocumentDiagnosticReport:
56445644
"""The actual items."""
56455645

56465646
related_documents: Optional[
5647-
Dict[
5647+
Mapping[
56485648
str,
56495649
Union[FullDocumentDiagnosticReport, "UnchangedDocumentDiagnosticReport"],
56505650
]
@@ -5705,7 +5705,7 @@ class RelatedUnchangedDocumentDiagnosticReport:
57055705
diagnostic request for the same document."""
57065706

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

0 commit comments

Comments
 (0)