codegen-2 2.12.2__tar.gz → 2.14.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.12.2
3
+ Version: 2.14.0
4
4
  Summary: Meta-programming
5
5
  License: MIT
6
6
  Author: Binh Vu
@@ -101,6 +101,7 @@ class AST:
101
101
  return_type: Optional[Expr] = None,
102
102
  is_async: bool = False,
103
103
  is_static: bool = False,
104
+ modifiers: Optional[Sequence[Literal["get", "set"]]] = None,
104
105
  comment: str = "",
105
106
  ):
106
107
  """Define a function. The input variables are deferred vars as they are created for this function (i.e., must not be predefined prior to this function)"""
@@ -115,6 +116,7 @@ class AST:
115
116
  var.name, var.key, grandchild_id, var.force_name, var.type
116
117
  )
117
118
  )
119
+
118
120
  return self._add_stmt(
119
121
  DefFuncStatement(
120
122
  name,
@@ -129,6 +131,7 @@ class AST:
129
131
  return_type,
130
132
  is_async,
131
133
  is_static,
134
+ modifiers or [],
132
135
  comment,
133
136
  )
134
137
  )
@@ -308,6 +308,13 @@ class PredefinedFn:
308
308
  def to_python(self):
309
309
  return f"({', '.join([item.to_python() for item in self.items])})"
310
310
 
311
+ @dataclass
312
+ class set(Expr):
313
+ items: Sequence[Expr]
314
+
315
+ def to_python(self):
316
+ return f"{{{', '.join([item.to_python() for item in self.items])}}}"
317
+
311
318
  @dataclass
312
319
  class list(Expr):
313
320
  items: Sequence[Expr]
@@ -90,6 +90,9 @@ class DefFuncStatement(Statement):
90
90
  return_type: Optional[Expr] = None
91
91
  is_async: bool = False
92
92
  is_static: bool = False
93
+ # modifiers to the function such as get or set, usually appear after the static, function definition, async keywords.
94
+ # to mark this function as a getter or setter.
95
+ modifiers: Sequence[Literal["get", "set"]] = field(default_factory=list)
93
96
  comment: str = ""
94
97
 
95
98
  def to_python(self):
@@ -99,6 +102,7 @@ class DefFuncStatement(Statement):
99
102
  if self.is_async:
100
103
  sig = "async " + sig
101
104
  sig = sig + ":"
105
+
102
106
  if self.is_static:
103
107
  sig = "@staticmethod\n" + sig
104
108
  if self.comment != "":
@@ -121,6 +125,9 @@ class DefFuncStatement(Statement):
121
125
  if self.is_static:
122
126
  keyword += "static "
123
127
 
128
+ if len(self.modifiers) > 0:
129
+ keyword += " ".join(self.modifiers) + " "
130
+
124
131
  sig = (
125
132
  keyword
126
133
  + f"{self.name}({', '.join([arg[0].to_typescript() + " = " + arg[1].to_typescript() if isinstance(arg, tuple) else arg.to_typescript() for arg in self.args])})"
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "codegen-2"
3
- version = "2.12.2"
3
+ version = "2.14.0"
4
4
  description = "Meta-programming"
5
5
  authors = ["Binh Vu <binh@toan2.com>"]
6
6
  license = "MIT"
File without changes
File without changes