codegen-2 2.15.7__tar.gz → 2.16.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.15.7
3
+ Version: 2.16.0
4
4
  Summary: Meta-programming
5
5
  Author: Binh Vu
6
6
  Author-email: Binh Vu <binh@toan2.com>
@@ -11,7 +11,6 @@ from codegen.models.statement import (
11
11
  Comment,
12
12
  DefClassLikeStatement,
13
13
  DefClassStatement,
14
- DefClassVarStatement,
15
14
  DefFuncStatement,
16
15
  ElseStatement,
17
16
  ExceptionStatement,
@@ -19,7 +18,6 @@ from codegen.models.statement import (
19
18
  IfStatement,
20
19
  ImportStatement,
21
20
  LineBreak,
22
- NoStatement,
23
21
  PythonStatement,
24
22
  ReturnStatement,
25
23
  SingleExprStatement,
@@ -87,7 +87,7 @@ class ExprConstant(Expr):
87
87
  return "null"
88
88
  if isinstance(val, (str, int, float)):
89
89
  return json.dumps(val)
90
- if isinstance(val, list):
90
+ if isinstance(val, (list, tuple)):
91
91
  return (
92
92
  "["
93
93
  + ", ".join([ExprConstant.constant_to_typescript(v) for v in val])
@@ -432,6 +432,86 @@ class PredefinedFn:
432
432
  return f"{self.collection.to_typescript()}.filter((_x: any) => {self.filter.to_typescript()}).map((_x: any) => {self.func.to_typescript()})"
433
433
  return f"{self.collection.to_typescript()}.map((_x: any) => {self.func.to_typescript()})"
434
434
 
435
+ @dataclass(init=False)
436
+ class map_list_as_set(Expr):
437
+ collection: Expr
438
+ func: Expr
439
+ filter: Optional[Expr] = None
440
+
441
+ def __init__(
442
+ self,
443
+ collection: Expr,
444
+ func: Callable[[ExprIdent], Expr],
445
+ filter: Optional[Callable[[ExprIdent], Expr]] = None,
446
+ ):
447
+ self.collection = collection
448
+ self.func = func(ExprIdent("_x"))
449
+ self.filter = filter(ExprIdent("_x")) if filter is not None else None
450
+
451
+ def to_python(self):
452
+ if self.filter is not None:
453
+ return f"{{{self.func.to_python()} for _x in {self.collection.to_python()} if {self.filter.to_python()}}}"
454
+ return (
455
+ f"{{{self.func.to_python()} for _x in {self.collection.to_python()}}}"
456
+ )
457
+
458
+ def to_typescript(self):
459
+ if self.filter is not None:
460
+ return f"new Set({self.collection.to_typescript()}.filter((_x: any) => {self.filter.to_typescript()}).map((_x: any) => {self.func.to_typescript()}))"
461
+ return f"new Set({self.collection.to_typescript()}.map((_x: any) => {self.func.to_typescript()}))"
462
+
463
+ @dataclass(init=False)
464
+ class flatten_map_list(Expr):
465
+ collection: Expr
466
+ func: Expr
467
+ filter: Optional[Expr] = None
468
+
469
+ def __init__(
470
+ self,
471
+ collection: Expr,
472
+ func: Callable[[ExprIdent], Expr],
473
+ filter: Optional[Callable[[ExprIdent], Expr]] = None,
474
+ ):
475
+ self.collection = collection
476
+ self.func = func(ExprIdent("_x"))
477
+ self.filter = filter(ExprIdent("_x")) if filter is not None else None
478
+
479
+ def to_python(self):
480
+ if self.filter is not None:
481
+ return f"[_y for _x in {self.collection.to_python()} for _y in {self.func.to_python()} if {self.filter.to_python()}]"
482
+ return f"[_y for _x in {self.collection.to_python()} for _y in {self.func.to_python()}]"
483
+
484
+ def to_typescript(self):
485
+ if self.filter is not None:
486
+ return f"{self.collection.to_typescript()}.flatMap((_x: any) => {self.func.to_typescript()}).filter((_y: any) => {self.filter.to_typescript()})"
487
+ return f"{self.collection.to_typescript()}.flatMap((_x: any) => {self.func.to_typescript()})"
488
+
489
+ @dataclass(init=False)
490
+ class flatten_map_list_as_set(Expr):
491
+ collection: Expr
492
+ func: Expr
493
+ filter: Optional[Expr] = None
494
+
495
+ def __init__(
496
+ self,
497
+ collection: Expr,
498
+ func: Callable[[ExprIdent], Expr],
499
+ filter: Optional[Callable[[ExprIdent], Expr]] = None,
500
+ ):
501
+ self.collection = collection
502
+ self.func = func(ExprIdent("_x"))
503
+ self.filter = filter(ExprIdent("_y")) if filter is not None else None
504
+
505
+ def to_python(self):
506
+ if self.filter is not None:
507
+ return f"{{_y for _x in {self.collection.to_python()} for _y in {self.func.to_python()} if {self.filter.to_python()}}}"
508
+ return f"{{_y for _x in {self.collection.to_python()} for _y in {self.func.to_python()}}}"
509
+
510
+ def to_typescript(self):
511
+ if self.filter is not None:
512
+ return f"new Set({self.collection.to_typescript()}.flatMap((_x: any) => {self.func.to_typescript()}).filter((_y: any) => {self.filter.to_typescript()}))"
513
+ return f"new Set({self.collection.to_typescript()}.flatMap((_x: any) => {self.func.to_typescript()}))"
514
+
435
515
  @dataclass
436
516
  class range(Expr):
437
517
  start: Expr
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codegen-2"
3
- version = "2.15.7"
3
+ version = "2.16.0"
4
4
  description = "Meta-programming"
5
5
  authors = [{ name = "Binh Vu", email = "binh@toan2.com" }]
6
6
  license = { text = "MIT" }
File without changes