- Fixes regression in post cattrs-1.1.2 where attrs objects in
typing.Any
fields are returned as-is and not unstructured
- Fixes error in structuring parameterized generic wildcats
Breaking changes:
- Upgrades
cattrs
from 1.1.2 to 22.1.0,attrs
from 20.3.0 to 21.4.0 and switches to the GenConverter, which supports the newer style type annotations (e.g, list[] instead of typing.List[]). - Detailed validation from cattrs is enabled by default. Disable it if you wish by calling
set_detailed_validation_mode_not_threadsafe(enable=False)
- Removed
typecats.types.CommonStructuringExceptions
. Structuring validation errors are now alltypecats.StructuringError
s (aliased tocattrs.errors.BaseValidationError
), regardless of detailed validation. - MyPy plugin changed from resolving from
__builtins__.<type>
tobuiltins.<type>
to avoid errors. This might not work on older mypy versions.
Other changes:
- Exports
register_struc_hook_func
andregister_unstruc_hook_func
, which are methods bound to typecats's default cattrs converter. - Changed imports from
cattr
tocattrs
- Supports Python 3.8 and 3.9.
- Changed function parameter types from
cattrs.Converter
tocattrs.GenConverter
where necessary, though typecats assumesGenConverter
throughout, so you should probably update too.
- Correctly reference typing_extensions as a dependency in setup.py
- Upgrades
cattrs
from 1.0.0 to 1.1.2 andattrs
from 19.1.0 to 20.3.0, primarily to fix acattrs
bug wherein union field types where types in the union have defaults are not always correctly structured.
- Wildcats now properly implement
__eq__
to include the actual wildcat dictionary. Additionally, this fixes a bug whereunstruc_strip_defaults
did not properly strip attributes that themselves had unstructurable data.
Added new exception hook functionality for better visibility into structuring errors. By default adds verbose logging when your item fails to structure, but this default behavior may be replaced.
New converter which will strip (recursively) all attributes which are
equal to their attrs defaults, except for attributes annotated as
Literal
, which are assumed to be required.
Can be called using unstruc_strip_defaults(your_attrs_obj)
, or on a
Cat type using the new boolean keyword argument on unstruc
,
your_cats_obj.unstruc(strip_defaults=True)
.
No longer assume that the dict
methods will not be overlaid on a
Wildcat by attrs
attributes.
Extracted the default cattrs
Converter from all implementations to
make typecats
fully compatible with the use of any
application-provided Converter(s).
All that is necessary to use an externally-supplied converter is to
call the new patch_converter_for_typecats
function exported by the
package root on the Converter. This will patch your Converter to
enable typecats
functionality while still maintaining all the
existing functionality and previously-registered function-dispatched
structure and unstructure hooks within your Converter.
Reworked Wildcat functionality to use a cleaner hooking process.
Corrected return type of try_struc
to be Optional[T]
.
Improved mypy plugin that recognizes Mapping[str, Any]
as the
appropriate input type for struc
, and Optional[Mapping[str, Any]]
for try_struc
.
Also resolves the incompatibility with the mypy plugin API change in 0.750.
Wildcats will now unstructure their 'wild' key/value pairs instead of passing them through.
Improved structure exception logging.
Typecats will now preserve user-provided attrs
validators.
The non-empty validator will still be run on attributes without defaults.
No longer block __setitem__
, __getitem__
, and update
for keys
where the Wildcat class defines an attribute with the same name. Log
warnings instead. This more permissive behavior will allow a smoother
progression for code that was written before an attribute was
subsequently added (typed).
Added README and Github url to setup.py.
Initial release of typecats.