codegen-2 2.1.2__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.2
3
+ Version: 2.1.3
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -213,8 +213,6 @@ class AST:
213
213
  return VarScope(self.id, len(self.children))
214
214
 
215
215
  def _add_stmt(self, stmt: Statement):
216
- if isinstance(stmt, NoStatement):
217
- return self
218
216
  if self._is_frozen:
219
217
  raise Exception("The AST is frozen and cannot be modified")
220
218
  ast = AST(self.next_child_id(), self.prog, stmt)
@@ -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.2"
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