codegen-2 2.13.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: codegen-2
3
- Version: 2.13.0
3
+ Version: 2.15.0
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -308,6 +308,13 @@ class PredefinedFn:
308
308
  def to_python(self):
309
309
  return f"({', '.join([item.to_python() for item in self.items])})"
310
310
 
311
+ @dataclass
312
+ class set(Expr):
313
+ items: Sequence[Expr]
314
+
315
+ def to_python(self):
316
+ return f"{{{', '.join([item.to_python() for item in self.items])}}}"
317
+
311
318
  @dataclass
312
319
  class list(Expr):
313
320
  items: Sequence[Expr]
@@ -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
+ )
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "codegen-2"
3
- version = "2.13.0"
3
+ version = "2.15.0"
4
4
  description = "Meta-programming"
5
5
  authors = ["Binh Vu <binh@toan2.com>"]
6
6
  license = "MIT"
File without changes
File without changes