py2puml icon indicating copy to clipboard operation
py2puml copied to clipboard

handle attribute default value

Open lucsorel opened this issue 5 years ago • 2 comments

using the defaults attribute of the constructor method should help

getattr(definition_type.__init__, '__defaults__', None)
  • see this example for the way to display attribute with a default value: https://stackoverflow.com/a/36323868

lucsorel avatar May 14 '20 14:05 lucsorel

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

lucsorel avatar Jun 09 '20 21:06 lucsorel

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.

doyou89 avatar Jan 29 '21 07:01 doyou89