Skip to content

Commit

Permalink
Stub generator: use property decorators to represent mutable attribut…
Browse files Browse the repository at this point in the history
…es and properties
  • Loading branch information
shBLOCK committed Apr 5, 2024
1 parent 3ba286e commit 7a840d3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions codegen/stub_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import regex

#TODO: docstring

def convert_type(org: str) -> str:
types = []
for raw in map(str.strip, org.split("|")):
Expand All @@ -26,13 +28,22 @@ def __init__(self, name: str, ptype: str, mutable: bool = True):
self.mutable = mutable

def stub(self) -> list[str]:
# if self.mutable:
# return [f"{self.name}: {self.type}"]
# else:
# return [
# "@property",
# f"def {self.name}(self) -> {self.type}: ..."
# ]
stub = [
"@property",
f"def {self.name}(self) -> {self.type}: ..."
]
if self.mutable:
return [f"{self.name}: {self.type}"]
else:
return [
"@property",
f"def {self.name}(self) -> {self.type}: ..."
]
stub.append(f"@{self.name}.setter")
stub.append(f"def {self.name}(self, value: {self.type}) -> None: ...")
return stub


class StubMethod:
class Param:
Expand Down

0 comments on commit 7a840d3

Please sign in to comment.