codegen-2 2.1.1__tar.gz → 2.1.3__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.1
2
2
  Name: codegen-2
3
- Version: 2.1.1
3
+ Version: 2.1.3
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -15,6 +15,7 @@ from codegen.models.statement import (
15
15
  IfStatement,
16
16
  ImportStatement,
17
17
  LineBreak,
18
+ NoStatement,
18
19
  PythonStatement,
19
20
  ReturnStatement,
20
21
  SingleExprStatement,
@@ -176,6 +177,7 @@ class AST:
176
177
  else:
177
178
  for ast in self.children:
178
179
  if ast.find_ast(id) is not None:
180
+ yield self
179
181
  yield from ast.find_ast_to(id)
180
182
  break
181
183
 
@@ -13,6 +13,11 @@ class Expr(ABC):
13
13
  def to_python(self):
14
14
  raise NotImplementedError()
15
15
 
16
+ def to_wrapped_python(self):
17
+ if isinstance(self, (ExprVar, ExprConstant)):
18
+ return self.to_python()
19
+ return f"({self.to_python()})"
20
+
16
21
 
17
22
  class ExceptionExpr(Expr):
18
23
  pass
@@ -121,9 +126,7 @@ class ExprNegation(Expr):
121
126
  expr: Expr
122
127
 
123
128
  def to_python(self):
124
- if isinstance(self.expr, (ExprVar, ExprConstant)):
125
- return f"not {self.expr.to_python()}"
126
- return f"not ({self.expr.to_python()})"
129
+ return f"not {self.expr.to_wrapped_python()}"
127
130
 
128
131
 
129
132
  class PredefinedFn:
@@ -175,17 +178,7 @@ class PredefinedFn:
175
178
  item: Expr
176
179
 
177
180
  def to_python(self):
178
- if isinstance(self.set_, (ExprVar, ExprConstant)):
179
- set_py = self.set_.to_python()
180
- else:
181
- set_py = f"({self.set_.to_python()})"
182
-
183
- if isinstance(self.item, (ExprVar, ExprConstant)):
184
- item_py = self.item.to_python()
185
- else:
186
- item_py = f"({self.item.to_python()})"
187
-
188
- return f"{item_py} in {set_py}"
181
+ return f"{self.item.to_wrapped_python()} in {self.set_.to_wrapped_python()}"
189
182
 
190
183
  @dataclass
191
184
  class list_append(Expr):
@@ -193,7 +186,7 @@ class PredefinedFn:
193
186
  item: Expr
194
187
 
195
188
  def to_python(self):
196
- return f"{self.lst.to_python()}.append({self.item.to_python()})"
189
+ return f"{self.lst.to_wrapped_python()}.append({self.item.to_python()})"
197
190
 
198
191
  @dataclass
199
192
  class has_item(Expr):
@@ -201,7 +194,7 @@ class PredefinedFn:
201
194
  item: Expr
202
195
 
203
196
  def to_python(self):
204
- return f"({self.item.to_python()}) in {self.collection.to_python()}"
197
+ return f"{self.item.to_wrapped_python()} in {self.collection.to_wrapped_python()}"
205
198
 
206
199
  @dataclass
207
200
  class base_error(ExceptionExpr):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "codegen-2"
3
- version = "2.1.1"
3
+ version = "2.1.3"
4
4
  description = "Meta-programming"
5
5
  authors = ["Binh Vu <binh@toan2.com>"]
6
6
  license = "MIT"
File without changes
File without changes
File without changes