Define fields in python classes. Easily.
BSD-3-CLAUSE License
Bot releases are hidden (Show)
Published by smarie almost 4 years ago
autofields
(and therefore autoclass
too) where a field would be mistakenly recreated on a subclass when that subclass does not define type hints while the parent class defines type hints. Fixes #81
See documentation page for details.
Published by smarie about 4 years ago
autoclass
so as to get rid of the dependency. Since we are in a pyfields
context there were many things that could be dropped and remaining code could be easily copied over. Also took this opportunity to replace the dict view with a to_dict
/from_dict
pair of methods, this seems less intrusive in the class design. Finally the parameter names have been simplified, see API reference for details. Fixes #79
See documentation page for details.
Published by smarie about 4 years ago
@autoclass
so that it is much easier to access the relevant arguments from underlying @autofields
and @autoclass
. Fixed #78
See documentation page for details.
Published by smarie about 4 years ago
@autoclass
decorator directly available from pyfields
. It is merely equivalent to the original @autoclass
with option autofields=True
, which makes it easier to use on classes with automatic fields. Fixes #75
See documentation page for details.
Published by smarie about 4 years ago
@autofields
even in the case of a field with just a type annotation. Fixed #76
See documentation page for details.
Published by smarie about 4 years ago
String forward references in type hints, and PEP563 behaviour, is now supported. When this case happense, the type hint resolution is delayed until the field is first accessed. Fixes #73
Accessing a field definition from a class directly is now enabled, since PyCharm fixed their autocompletion bug. Fixes #12
See documentation page for details.
Published by smarie over 4 years ago
getfields
can now be executed on an instance, and provides a public_only
option. Fixes #69
New get_field_values
method to get an ordered dict-like of field name: value. Fixes #70
See documentation page for details.
Published by smarie over 4 years ago
@autofields
now correctly skips @property
and more generally, descriptor members. Fixes #67
See documentation page for details.
Published by smarie over 4 years ago
setup.py
. In particular removed dependency to six
. Fixes #66
See documentation page for details.
Published by smarie over 4 years ago
tests
folder is now excluded from generated package wheel. Fixed #65
See documentation page for details.
Published by smarie over 4 years ago
converters={'*': ...}
does not appear as a type hint error. Fixed #64
See documentation page for details.
Published by smarie almost 5 years ago
See documentation page for details.
Published by smarie almost 5 years ago
New @autofields
decorator. This decorator can be used to drastically reduce boilerplate code, similar to pydantic
and attrs
. This is compliant with python 2.7 and 3.5+ but is more useful when the type hints can be provided in class member annotations, so from 3.6+. Fixed #55
Default values are now validated/converted as normal values. If the default value is provided in default=<value>
or as a default_factory=copy_value(<value>)
, this is done only once per field, to accelerate future access. If the value was converted on the way, the converted value is used to replace the default value, or the default value copied by the factory. Fixed #57
Misc: removed makefun
usage in validate_n_convert.py
: was overkill. Also fixed a few type hints.
See documentation page for details.
Published by smarie almost 5 years ago
super().__init__
not behaving as expected. Fixed #53
See documentation page for details.
Published by smarie almost 5 years ago
nonable
status was wrongly overriden automatically when the field was attached to the class. Fixed #51
typeguard
is used and a tuple of types is provided instead of a Union
. Fixed #52
See documentation page for details.
Published by smarie almost 5 years ago
Added pyproject.toml
See documentation page for details.
Published by smarie almost 5 years ago
Overall behaviour stabilized and compliance with @autoclass
to cover most use cases.
The only bug that has not yet been fixed is #12
See documentation page for details.
Published by smarie almost 5 years ago
API
new helper methods get_field
, yield_fields
, has_fields
and get_fields
(new name of collect_all_fields
) so that other libraries such as autoclass
can easily access the various information. fix_fields
removed. Fixed #48
New ancestor_fields_first
option in all the __init__
makers (make_init
and @init_fields
). Fixed #50
Bugfixes
Bugfixes in all the __init__
makers (make_init
and @init_fields
):
bugfix in case of inheritance with override: #49
the argument order used for fields initialization (inside the generated init method body) was sometimes incorrect. This would trigger a bug when one field was requiring another one to initialize.
when the list of fields received by InitDescriptor
was an empty tuple and not None
, the constructor was not created properly
See documentation page for details.
Published by smarie about 5 years ago
nonable
, so as to bypass type and value validation when None
is received. Fixed #44
See documentation page for details.
Published by smarie about 5 years ago
FieldTypeError
. Fixed #40.See documentation page for details.