3
3
import os
4
4
from typing import (
5
5
TYPE_CHECKING ,
6
- Dict ,
7
- List ,
8
- Set ,
9
- Tuple ,
10
- Type ,
11
6
)
12
7
13
8
from ..casing import safe_snake_case
18
13
from ..plugin .models import PluginRequestCompiler
19
14
from ..plugin .typing_compiler import TypingCompiler
20
15
21
- WRAPPER_TYPES : Dict [str , Type ] = {
16
+ WRAPPER_TYPES : dict [str , type ] = {
22
17
".google.protobuf.DoubleValue" : google_protobuf .DoubleValue ,
23
18
".google.protobuf.FloatValue" : google_protobuf .FloatValue ,
24
19
".google.protobuf.Int32Value" : google_protobuf .Int32Value ,
31
26
}
32
27
33
28
34
- def parse_source_type_name (field_type_name : str , request : " PluginRequestCompiler" ) -> Tuple [str , str ]:
29
+ def parse_source_type_name (field_type_name : str , request : PluginRequestCompiler ) -> tuple [str , str ]:
35
30
"""
36
31
Split full source type name into package and type name.
37
32
E.g. 'root.package.Message' -> ('root.package', 'Message')
@@ -77,7 +72,7 @@ def get_type_reference(
77
72
imports : set ,
78
73
source_type : str ,
79
74
typing_compiler : TypingCompiler ,
80
- request : " PluginRequestCompiler" ,
75
+ request : PluginRequestCompiler ,
81
76
unwrap : bool = True ,
82
77
pydantic : bool = False ,
83
78
) -> str :
@@ -98,8 +93,8 @@ def get_type_reference(
98
93
99
94
source_package , source_type = parse_source_type_name (source_type , request )
100
95
101
- current_package : List [str ] = package .split ("." ) if package else []
102
- py_package : List [str ] = source_package .split ("." ) if source_package else []
96
+ current_package : list [str ] = package .split ("." ) if package else []
97
+ py_package : list [str ] = source_package .split ("." ) if source_package else []
103
98
py_type : str = pythonize_class_name (source_type )
104
99
105
100
compiling_google_protobuf = current_package == ["google" , "protobuf" ]
@@ -122,7 +117,7 @@ def get_type_reference(
122
117
return reference_cousin (current_package , imports , py_package , py_type )
123
118
124
119
125
- def reference_absolute (imports : Set [str ], py_package : List [str ], py_type : str ) -> str :
120
+ def reference_absolute (imports : set [str ], py_package : list [str ], py_type : str ) -> str :
126
121
"""
127
122
Returns a reference to a python type located in the root, i.e. sys.path.
128
123
"""
@@ -139,7 +134,7 @@ def reference_sibling(py_type: str) -> str:
139
134
return f"{ py_type } "
140
135
141
136
142
- def reference_descendent (current_package : List [str ], imports : Set [str ], py_package : List [str ], py_type : str ) -> str :
137
+ def reference_descendent (current_package : list [str ], imports : set [str ], py_package : list [str ], py_type : str ) -> str :
143
138
"""
144
139
Returns a reference to a python type in a package that is a descendent of the
145
140
current package, and adds the required import that is aliased to avoid name
@@ -157,7 +152,7 @@ def reference_descendent(current_package: List[str], imports: Set[str], py_packa
157
152
return f"{ string_import } .{ py_type } "
158
153
159
154
160
- def reference_ancestor (current_package : List [str ], imports : Set [str ], py_package : List [str ], py_type : str ) -> str :
155
+ def reference_ancestor (current_package : list [str ], imports : set [str ], py_package : list [str ], py_type : str ) -> str :
161
156
"""
162
157
Returns a reference to a python type in a package which is an ancestor to the
163
158
current package, and adds the required import that is aliased (if possible) to avoid
@@ -178,7 +173,7 @@ def reference_ancestor(current_package: List[str], imports: Set[str], py_package
178
173
return string_alias
179
174
180
175
181
- def reference_cousin (current_package : List [str ], imports : Set [str ], py_package : List [str ], py_type : str ) -> str :
176
+ def reference_cousin (current_package : list [str ], imports : set [str ], py_package : list [str ], py_type : str ) -> str :
182
177
"""
183
178
Returns a reference to a python type in a package that is not descendent, ancestor
184
179
or sibling, and adds the required import that is aliased to avoid name conflicts.
0 commit comments