Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a howard decorator #1

Open
nhumrich opened this issue Oct 3, 2018 · 2 comments
Open

Make a howard decorator #1

nhumrich opened this issue Oct 3, 2018 · 2 comments

Comments

@nhumrich
Copy link
Owner

nhumrich commented Oct 3, 2018

Could have a class decorator that adds the fromdict and todict methods to the class as classmethods.

example:

@howard.howard
@dataclass
class Person:
    name: str
    age: int

my_dict = {'name': 'Bob', 'age': 24}
person = Person.fromdict(my_dict)
@iddan
Copy link

iddan commented Nov 22, 2018

I think you better be off with inheriting a class because as of now you can't tell mypy that a decorator adds method to the class it's applied to.

Ogaday added a commit to Ogaday/howard that referenced this issue Feb 28, 2020
I want to be able to load and dump numerous unsupported types using
Howard. This functionality allows loading/dumping functions to be
specified at conversion time, on a per class basis. In the future I can
imagine a howard class to which you can pass your custom encoders and
other arguments (such as public/strict) so that the same arguments don't
need to be passed at each call of from_dict/to_dict. This could also tie
into nhumrich#1 - either as a decorator or mixin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants