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

handle attribute default value #3

Open
lucsorel opened this issue May 14, 2020 · 2 comments
Open

handle attribute default value #3

lucsorel opened this issue May 14, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@lucsorel
Copy link
Owner

using the defaults attribute of the constructor method should help

getattr(definition_type.__init__, '__defaults__', None)
@lucsorel lucsorel added the enhancement New feature or request label May 14, 2020
@lucsorel
Copy link
Owner Author

lucsorel commented Jun 9, 2020

default values of named tuples can be handled with the _fields_defaults attribute (see #5)

@doyou89
Copy link
Contributor

doyou89 commented Jan 29, 2021

for p, v in inspect.signature(definition_type.__init__).parameters.items():

will give the defaults and types of the parameters of the constructor.
v.default is the default value. v.default will be inspect.Parameter.empty if the default value is not given.
v.annotation is the type of the parameter. v.annotation will be inspect.Parameter.empty if the type of parameter is not given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants