codegen-2 2.1.0__tar.gz → 2.1.1__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.0
3
+ Version: 2.1.1
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -128,7 +128,9 @@ class AST:
128
128
  return self._add_stmt(IfStatement(condition))
129
129
 
130
130
  def else_(self):
131
- assert len(self.children) > 0 and isinstance(self.children[-1].stmt, Statement)
131
+ assert len(self.children) > 0 and isinstance(
132
+ self.children[-1].stmt, IfStatement
133
+ )
132
134
  return self._add_stmt(ElseStatement())
133
135
 
134
136
  def python_stmt(self, stmt: str) -> AST:
@@ -121,7 +121,9 @@ class ExprNegation(Expr):
121
121
  expr: Expr
122
122
 
123
123
  def to_python(self):
124
- return f"not {self.expr.to_python()}"
124
+ if isinstance(self.expr, (ExprVar, ExprConstant)):
125
+ return f"not {self.expr.to_python()}"
126
+ return f"not ({self.expr.to_python()})"
125
127
 
126
128
 
127
129
  class PredefinedFn:
@@ -173,7 +175,17 @@ class PredefinedFn:
173
175
  item: Expr
174
176
 
175
177
  def to_python(self):
176
- return f"({self.item.to_python()}) in {self.set_.to_python()}"
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}"
177
189
 
178
190
  @dataclass
179
191
  class list_append(Expr):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "codegen-2"
3
- version = "2.1.0"
3
+ version = "2.1.1"
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