codegen-2 2.7.2__tar.gz → 2.8.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.7.2
3
+ Version: 2.8.0
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -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
  [tool.poetry]
2
2
  name = "codegen-2"
3
- version = "2.7.2"
3
+ version = "2.8.0"
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