@@ -92,6 +92,28 @@ def infer_typing_attr(node, context=None):
9292 return node .infer (context = context )
9393
9494
95+ def _looks_like_typedDict ( # pylint: disable=invalid-name
96+ node : nodes .FunctionDef ,
97+ ) -> bool :
98+ """Check if node is TypedDict FunctionDef."""
99+ return isinstance (node , nodes .FunctionDef ) and node .name == "TypedDict"
100+
101+
102+ def infer_typedDict ( # pylint: disable=invalid-name
103+ node : nodes .FunctionDef , ctx : context .InferenceContext = None
104+ ) -> None :
105+ """Replace TypedDict FunctionDef with ClassDef."""
106+ class_def = nodes .ClassDef (
107+ name = "TypedDict" ,
108+ doc = node .doc ,
109+ lineno = node .lineno ,
110+ col_offset = node .col_offset ,
111+ parent = node .parent ,
112+ )
113+ class_def .postinit (bases = [], body = [], decorators = None )
114+ node .root ().locals ["TypedDict" ] = [class_def ]
115+
116+
95117GET_ITEM_TEMPLATE = """
96118@classmethod
97119def __getitem__(cls, value):
@@ -124,28 +146,6 @@ def create_typing_metaclass():
124146 return typing_meta
125147
126148
127- def _looks_like_typedDict ( # pylint: disable=invalid-name
128- node : nodes .FunctionDef ,
129- ) -> bool :
130- """Check if node is TypedDict FunctionDef."""
131- return isinstance (node , nodes .FunctionDef ) and node .name == "TypedDict"
132-
133-
134- def infer_typedDict ( # pylint: disable=invalid-name
135- node : nodes .FunctionDef , ctx : context .InferenceContext = None
136- ) -> None :
137- """Replace TypedDict FunctionDef with ClassDef."""
138- class_def = nodes .ClassDef (
139- name = "TypedDict" ,
140- doc = node .doc ,
141- lineno = node .lineno ,
142- col_offset = node .col_offset ,
143- parent = node .parent ,
144- )
145- class_def .postinit (bases = [], body = [], decorators = None )
146- node .root ().locals ["TypedDict" ] = [class_def ]
147-
148-
149149def _looks_like_typing_alias (node : nodes .Call ) -> bool :
150150 """
151151 Returns True if the node corresponds to a call to _alias function.
0 commit comments