codegen-2 2.7.2__py3-none-any.whl → 2.8.1__py3-none-any.whl

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/models/expr.py CHANGED
@@ -219,6 +219,8 @@ class ExprNegation(Expr):
219
219
  expr: Expr
220
220
 
221
221
  def to_python(self):
222
+ if isinstance(self.expr, ExprIs):
223
+ return f"{self.expr.left.to_python()} is not {self.expr.right.to_python()}"
222
224
  return f"not {self.expr.to_wrapped_python()}"
223
225
 
224
226
 
@@ -253,6 +253,24 @@ class ExceptionStatement(Statement):
253
253
  return "raise " + self.expr.to_python()
254
254
 
255
255
 
256
+ @dataclass
257
+ class AssertionStatement(Statement):
258
+ expr: Expr
259
+ error_msg: Optional[Expr] = None
260
+
261
+ def to_python(self):
262
+ if self.error_msg:
263
+ return f"assert {self.expr.to_python()}, {self.error_msg.to_python()}"
264
+ return f"assert {self.expr.to_python()}"
265
+
266
+ def to_typescript(self):
267
+ if self.error_msg:
268
+ return f"if (!({self.expr.to_typescript()})) throw new Error({self.error_msg.to_typescript()});"
269
+ return (
270
+ f"if (!({self.expr.to_typescript()})) throw new Error('Assertion failed');"
271
+ )
272
+
273
+
256
274
  @dataclass
257
275
  class ForLoopStatement(Statement):
258
276
  item: Var
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: codegen-2
3
- Version: 2.7.2
3
+ Version: 2.8.1
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -1,12 +1,12 @@
1
1
  codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  codegen/models/__init__.py,sha256=j__FrDdGOILIo9jqEDElL3YP69h0xkL2SqrMxSqgpTc,457
3
3
  codegen/models/ast.py,sha256=qq1xeWCMbTUXoOXszVYYPTaN-eiPJHdoTbsYbz5MKUo,10518
4
- codegen/models/expr.py,sha256=TjCDeNhwYKuVtIB0eIRNYQ5cLBC1QGajkGQniKPp4y4,11084
4
+ codegen/models/expr.py,sha256=nmUd3rr4WDYZ83WihD8wRPiw9gJz5UJQFjZIc-n7PWM,11214
5
5
  codegen/models/program.py,sha256=mrvtOp9WpaZ6B5KOGpFFLBXMtSCo-BpuGCEgipUuBV8,5062
6
- codegen/models/statement.py,sha256=fnhs9g40l_yHeSpUmvohJdL4G6IbMtnC1Yik5axmLhI,8874
6
+ codegen/models/statement.py,sha256=wyn4245e0eVXPnsKU8SifOA8uDZzD1SoNzGe5CT_n18,9442
7
7
  codegen/models/types.py,sha256=Dl-wzGB1viA7EZj2CuTrZe1F133Q6ENVr_yRqxhde8M,178
8
8
  codegen/models/var.py,sha256=sOzDrqJHkAgA2Tqhh6IelW3dDe2o7us6HPjaRBVKmCQ,2722
9
- codegen_2-2.7.2.dist-info/LICENSE,sha256=Ea6itrykT9pvPGd0Kgl6FbrqdDwKswPZJmXMFVjUBqw,1064
10
- codegen_2-2.7.2.dist-info/METADATA,sha256=XemQZ6UDbMMAey9OMKkRNDN0DVSq41MvWTTFyuEWc_c,487
11
- codegen_2-2.7.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
12
- codegen_2-2.7.2.dist-info/RECORD,,
9
+ codegen_2-2.8.1.dist-info/LICENSE,sha256=Ea6itrykT9pvPGd0Kgl6FbrqdDwKswPZJmXMFVjUBqw,1064
10
+ codegen_2-2.8.1.dist-info/METADATA,sha256=zdccB4v1pFGt1S2ZlXw2KqNexTPyE5E1h7ifFXCUrTc,487
11
+ codegen_2-2.8.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
12
+ codegen_2-2.8.1.dist-info/RECORD,,