Changelog¶
1.7.2 - bugfix¶
- Fixed
TypeError: Neither typeguard not pytypes is installedeven withtypeguardinstalled. Fixed [#91] (https://github.com/smarie/python-pyfields/issues/91)
1.7.1 - Compatibility fix for typeguard 3.0.0¶
- Fixed
TypeError: check_type() takes 2 positional arguments but 3 were giventriggering erroneousFieldTypeErrorwhentypeguard>=3.0.0is used. Fixed #87
1.7.0 - Better support for non-deep-copiable default values in @autofields¶
-
@autofieldsand@autoclassnow raise an error when a field definition can not be valid, because the default value can not be deep-copied. This will help users detect issues such as #84 earlier. Implementation is done through a newautocheckoption in thecopy_valuefactory. -
@autofieldsand@autoclassnow provide anexclude(resp.af_exclude) list, to list names for fields that should not be created. By default this contains a reserved name fromabc.ABCMeta, for convenience. Fixes #84.
1.6.2 - CI/CD migration¶
- This is a technical release with no code change, to validate the new Github Actions workflow.
1.6.1 - Bugfix¶
- Fixed an issue with
autofields(and thereforeautoclasstoo) 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
1.6.0 - we now have our own version of @autoclass¶
- Copied the relevant contents from
autoclassso as to get rid of the dependency. Since we are in apyfieldscontext 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 ato_dict/from_dictpair of methods, this seems less intrusive in the class design. Finally the parameter names have been simplified, see API reference for details. Fixes #79
1.5.0 - updated @autoclass signature¶
- Improved
@autoclassso that it is much easier to access the relevant arguments from underlying@autofieldsand@autoclass. Fixed #78
1.4.0 - new @autoclass decorator¶
- New
@autoclassdecorator directly available frompyfields. It is merely equivalent to the original@autoclasswith optionautofields=True, which makes it easier to use on classes with automatic fields. Fixes #75
1.3.2 - bugfix¶
- Fields order are preserved by
@autofieldseven in the case of an explicitfield()with all others implicit. Fixed #77
1.3.1 - bugfix¶
- Fields order are preserved by
@autofieldseven in the case of a field with just a type annotation. Fixed #76
1.3.0 - Support for Forward references, PEP563 and class-level access¶
-
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
1.2.0 - getfields improvements and new get_field_values¶
-
getfieldscan now be executed on an instance, and provides apublic_onlyoption. Fixes #69 -
New
get_field_valuesmethod to get an ordered dict-like of field name: value. Fixes #70
1.1.5 - bugfix¶
@autofieldsnow correctly skips@propertyand more generally, descriptor members. Fixes #67
1.1.4 - better python 2 packaging¶
- packaging improvements: set the "universal wheel" flag to 1, and cleaned up the
setup.py. In particular removed dependency tosix. Fixes #66
1.1.3 - smaller wheel¶
testsfolder is now excluded from generated package wheel. Fixed #65
1.1.2 - type hint fix (minor)¶
- Now
converters={'*': ...}does not appear as a type hint error. Fixed #64
1.1.1 - PEP561 compatibility¶
- Misc: Package is now PEP561 compatible. Fixed #61
1.1.0 - @autofields and default values improvements¶
-
New
@autofieldsdecorator. This decorator can be used to drastically reduce boilerplate code, similar topydanticandattrs. 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 adefault_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
makefunusage invalidate_n_convert.py: was overkill. Also fixed a few type hints.
1.0.3 - bugfix¶
- Fixed bug with
super().__init__not behaving as expected. Fixed #53
1.0.2 - bugfixes¶
- User-provided
nonablestatus was wrongly overriden automatically when the field was attached to the class. Fixed #51 - Fixed an issue with type validation when
typeguardis used and a tuple of types is provided instead of aUnion. Fixed #52
1.0.1 - pyproject.toml¶
Added pyproject.toml
1.0.0 - Stable version¶
Overall behaviour stabilized and compliance with @autoclass to cover most use cases.
The only bug that has not yet been fixed is #12
0.14.0 - helpers, bugfix, and ancestor-first option in init makers¶
API
-
new helper methods
get_field,yield_fields,has_fieldsandget_fields(new name ofcollect_all_fields) so that other libraries such asautoclasscan easily access the various information.fix_fieldsremoved. Fixed #48 -
New
ancestor_fields_firstoption in all the__init__makers (make_initand@init_fields). Fixed #50
Bugfixes
-
Bugfixes in all the
__init__makers (make_initand@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
InitDescriptorwas an empty tuple and notNone, the constructor was not created properly
-
0.13.0 - nonable fields¶
- Fields can now be
nonable, so as to bypass type and value validation whenNoneis received. Fixed #44
0.12.0 - Minor improvements¶
- Now all type validation errors are
FieldTypeError. Fixed #40. - Fixed bug with python < 3.6 where fields were not automatically attached to their class when used from within a subclass first. Fixed #41
0.11.0 - Better initialization orders in generated __init__¶
Fixed fields initialization order in generated constructor methods:
- the order is now the same than the order of appearance in the class (and not reversed as it was). Fixed #36.
- the above is true, even in python < 3.6. Fixed #38
- the order now takes into account first the ancestors and then the subclasses, for the most intuitive behaviour. Fixed #37.
0.10.0 - Read-only fields + minor improvements¶
Read-only fields
- Read-only fields are now supported through
field(read_only=True). Fixes #33.
Misc
- All core exceptions now derive from a common
FieldError, for easier exception handling. - Now raising an explicit
ValueErrorwhen a descriptor field is used with an old-style class in python 2. Fixes #34
0.9.1 - Minor improvements¶
- Minor performance improvement:
Converter.create_from_fun()does not generate a newtypeeverytime a converter needs to be created from a callable - now a single classConverterWithFuncsis used. Fixed #32.
0.9.0 - Converters¶
converters
- Fields can now be equipped with converters by using
field(converters=...). Fixes #5 - New method
trace_convertto debug conversion issues. It is available both as an independent function and as a method onField. Fixes #31 - New decorator
@<field>.converterto add a converter to a field. Fixed #28.
misc
- The base
Fieldclass is now exposed at package level.
0.8.0 - PEP484 support¶
PEP484 type hints support
- Now type hints relying on the
typingmodule (PEP484) are correctly checked using whatever 3d party type checking library is available (typeguardis first looked for, thenpytypesas a fallback). If none of these providers are available, a fallback implementation is provided, basically flatteningUnions and replacingTypeVars before doingis_instance. It is not guaranteed to support alltypingsubtelties. Fixes #7
0.7.0 - more ways to define validators¶
validators
- New decorator
@<field>.validatorto add a validator to a field. Fixed #9. - Native fields are automatically transformed into descriptor fields when validators are added this way. Fixes #1.
0.6.0 - default factories and slots¶
default value factories
default_factorycallables now receive one argument: the object instance. Fixes #6- New decorator
@<field>.default_factoryto define a default value factory. Fixed #27 - New
copy_value,copy_fieldandcopy_attrhelper functions to create default value factories. Fixed #26
support for slots
fieldnow automatically detects when a native field is attached to a class with slots and no__dict__is present. In that case, the native field is replaced with a descriptor field. Fixed #20.
0.5.0 - First public version¶
fields
-
field()method to easily define class fields without necessarily defining a__init__. -
"native" fields are created by default, or if
native=Trueis set. ANativeFieldis a non-data descriptor that replaces itself automatically with a native python attribute after the first read, to get the same performance level on later access. -
"descriptor" fields are created when type or value validation is required, or if
native=Falseis set. ADescriptorFielduses the standard python descriptor protocol so that type and value can be validated on all future access without messing with the__setattr__method. -
support for
type_hintdeclaration to declare the type of a field. Ifvalidate_typeprovided, the descriptor will not be replaced with a native field, and the type will be checked on every value modification. ATypeErrorwill be raised if type does not comply. Type hints are correctly defined so that IDEs can pick them. Fixes #10 -
support for
validatorsrelying onvalid8. Validators can receive(val),(obj, val)or(obj, field, val)to support validation based on several fields. The only requirement is to returnTrueorNonein case of success. Fixes #3
init
-
make_initmethod to create an entire__init__method with control of which fields are injected, and with possibility to blend a post-init callback in. Fixes #14. -
@init_fieldsdecorator to auto-init fields before your__init__method. -
@inject_fieldsdecorator to easily injectfieldsin an init method and perform the assignment precisely when users want (for easy debugging). Fixes #13
misc
-
__weakref__added in all relevant classes. Fixes #21 -
Now using stubs #17
-
Fixed bug #11.
-
Fixed
ValueErrorwith mini-lambda < 2.2. Fixed #22 -
Because of a limitation in PyCharm type hints we had to remove support for class-level field access. This created #12 which will be fixed as soon as PyCharm issue is fixed.
0.1.0 - unpublished first draft¶
Extracted from mixture.