codegen-2 2.14.0__tar.gz → 2.15.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codegen_2-2.14.0 → codegen_2-2.15.0}/PKG-INFO +1 -1
- {codegen_2-2.14.0 → codegen_2-2.15.0}/codegen/models/program.py +21 -1
- {codegen_2-2.14.0 → codegen_2-2.15.0}/pyproject.toml +1 -1
- {codegen_2-2.14.0 → codegen_2-2.15.0}/LICENSE +0 -0
- {codegen_2-2.14.0 → codegen_2-2.15.0}/README.md +0 -0
- {codegen_2-2.14.0 → codegen_2-2.15.0}/codegen/__init__.py +0 -0
- {codegen_2-2.14.0 → codegen_2-2.15.0}/codegen/models/__init__.py +0 -0
- {codegen_2-2.14.0 → codegen_2-2.15.0}/codegen/models/ast.py +0 -0
- {codegen_2-2.14.0 → codegen_2-2.15.0}/codegen/models/expr.py +0 -0
- {codegen_2-2.14.0 → codegen_2-2.15.0}/codegen/models/statement.py +0 -0
- {codegen_2-2.14.0 → codegen_2-2.15.0}/codegen/models/types.py +0 -0
- {codegen_2-2.14.0 → codegen_2-2.15.0}/codegen/models/var.py +0 -0
|
@@ -6,7 +6,7 @@ from typing import Optional
|
|
|
6
6
|
|
|
7
7
|
from codegen.models.ast import AST
|
|
8
8
|
from codegen.models.expr import ExprIdent # You may need to adjust this import path
|
|
9
|
-
from codegen.models.statement import BlockStatement
|
|
9
|
+
from codegen.models.statement import BlockStatement, IfStatement
|
|
10
10
|
from codegen.models.types import AST_ID, KEY
|
|
11
11
|
from codegen.models.var import Var, VarScope
|
|
12
12
|
|
|
@@ -169,3 +169,23 @@ class ImportHelper:
|
|
|
169
169
|
assert ident in self.idents, ident
|
|
170
170
|
self.program.import_(self.idents[ident], True)
|
|
171
171
|
return ExprIdent(ident)
|
|
172
|
+
|
|
173
|
+
def python_import_for_hint(
|
|
174
|
+
self, module: str, is_import_attr: bool, alias: Optional[str] = None
|
|
175
|
+
):
|
|
176
|
+
"""A specific function only for Python to import identifiers that causing circular import error into a same TYPE_CHECKING condition"""
|
|
177
|
+
if module in self.program.imported_modules:
|
|
178
|
+
return
|
|
179
|
+
self.program.imported_modules.add(module)
|
|
180
|
+
|
|
181
|
+
self.program.import_("typing.TYPE_CHECKING", True)
|
|
182
|
+
for child in self.program.import_area.children:
|
|
183
|
+
if isinstance(child.stmt, IfStatement) and child.stmt.cond == ExprIdent(
|
|
184
|
+
"TYPE_CHECKING"
|
|
185
|
+
):
|
|
186
|
+
child.import_(module, is_import_attr, alias)
|
|
187
|
+
break
|
|
188
|
+
else:
|
|
189
|
+
self.program.import_area.if_(ExprIdent("TYPE_CHECKING"))(
|
|
190
|
+
lambda ast: ast.import_(module, is_import_attr, alias)
|
|
191
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|