-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YT-PYCC-14: Extend the const_class decorator with a new function
Added a `new` function to the `const_class` decorator, which returns a new instance of the class and allows for modifying the individual members of the new instance using `**kwargs`
- Loading branch information
1 parent
b2496a4
commit b606531
Showing
12 changed files
with
176 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import constclasses as cc | ||
|
||
|
||
@cc.const_class(with_kwargs=True) | ||
class PersonKwargs: | ||
first_name: str | ||
last_name: str | ||
age: int | ||
|
||
def __repr__(self) -> str: | ||
return f"(kwargs) {self.first_name} {self.last_name} [age: {self.age}]" | ||
|
||
|
||
@cc.const_class(with_kwargs=False) | ||
class PersonArgs: | ||
first_name: str | ||
last_name: str | ||
age: int | ||
|
||
def __repr__(self) -> str: | ||
return f"(args) {self.first_name} {self.last_name} [age: {self.age}]" | ||
|
||
|
||
if __name__ == "__main__": | ||
john = PersonKwargs(first_name="John", last_name="Doe", age=21) | ||
print(f"{john = }") | ||
|
||
john_aged = john.new(age=22) | ||
print(f"{john_aged = }") | ||
|
||
john = PersonArgs("John", "Doe", 21) | ||
print(f"{john = }") | ||
|
||
john_aged = john.new(age=22) | ||
print(f"{john_aged = }") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters