Removed BaseRegistry.__dir__(). Use BaseRegistry.keys() instead.
BaseRegistry.__iter__ now returns an iterator instead of a generator.
Removed BaseMutableRegistry.__setitem__(). Use BaseMutableRegistry.register() or RegistryPatcher instead.
Removed BaseMutableRegistry.__delitem__(). Use BaseMutableRegistry.unregister() instead.
MRO changes
BaseRegistry no longer extends typing.Mapping (it now extends typing.Container).
The signatures of BaseRegistry.items() and BaseRegistry.values() conflict with those of the corresponding methods in typing.Mapping, thereby violating the Liskov Substitution Principle.
BaseMutableRegistry no longer extends typing.MutableMapping.
The signature of BaseMutableRegistry.__setitem__() conflicts with that of the corresponding method in typing.MutableMapping, thereby violating the Liskov Substitution Principle.
Changed signatures
These changes only impact your code if you've created classes that derive from ClassRegistry and override the following methods. If your code is impacted, it shouldn't generate any runtime errors, but it may cause your IDE to warn about incompatible signatures and/or generate mypy errors.
ClassRegistry.__missing__ is now expected to return a class (or raise an exception); previously it could return any type, including None.
ClassRegistry.get_class is now expected to return a class; previously it could return any type, including None.
SortedClassRegistry now defines keys() instead of items().
If your code is impacted by the above changes, please post an issue describing your use case, so that I can have a look.
⚠️ Deprecations
BaseRegistry.values() is deprecated and will be removed in a future version of ClassRegistry. Use BaseRegistry.classes() instead.
BaseRegistry.items() is deprecated and will be removed in a future version of ClassRegistry. Use zip(registry.keys(), registry.classes()) instead.
Major changes
ClassRegistry now accepts an optional type parameter, to indicate the type of objects that it can create. Example:
registry = ClassRegistry[Pokemon]()
...
# IDE will infer that `fighter` is a `Pokemon` instance.
fighter = registry['grass']
ClassRegistryInstanceCache now accepts an optional type parameter, or infers it from the ClassRegistry that it wraps. Example:
registry = ClassRegistry[Pokemon]()
pokedex = ClassRegistryInstanceCache(registry)
...
# IDE will infer that `fighter` is a `Pokemon` instance.
fighter = pokedex['grass']
# This also works:
pokedex = ClassRegistryInstanceCache[Pokemon](registry)
Minor changes
ClassRegistryInstanceCache now extends typing.Mapping.
Added ClassRegistryInstanceCache.__len__().
BaseRegistry.__len__() is no longer abstract.
Cleared out some obsolete backwards-compatibility logic.
Integrated mypy into autohooks and CI, and fixed mypy-reported issues.
closes #15 (thanks @VRichardJP for suggesting!)
⚠️ Backwards-incompatible changes
BaseRegistry.__dir__()
. UseBaseRegistry.keys()
instead.BaseRegistry.__iter__
now returns an iterator instead of a generator.BaseMutableRegistry.__setitem__()
. UseBaseMutableRegistry.register()
orRegistryPatcher
instead.BaseMutableRegistry.__delitem__()
. UseBaseMutableRegistry.unregister()
instead.MRO changes
BaseRegistry
no longer extendstyping.Mapping
(it now extendstyping.Container
).BaseRegistry.items()
andBaseRegistry.values()
conflict with those of the corresponding methods intyping.Mapping
, thereby violating the Liskov Substitution Principle.BaseMutableRegistry
no longer extendstyping.MutableMapping
.BaseMutableRegistry.__setitem__()
conflicts with that of the corresponding method intyping.MutableMapping
, thereby violating the Liskov Substitution Principle.Changed signatures
These changes only impact your code if you've created classes that derive from
ClassRegistry
and override the following methods. If your code is impacted, it shouldn't generate any runtime errors, but it may cause your IDE to warn about incompatible signatures and/or generate mypy errors.ClassRegistry.__missing__
is now expected to return a class (or raise an exception); previously it could return any type, includingNone
.ClassRegistry.get_class
is now expected to return a class; previously it could return any type, includingNone
.SortedClassRegistry
now defineskeys()
instead ofitems()
.If your code is impacted by the above changes, please post an issue describing your use case, so that I can have a look.
⚠️ Deprecations
BaseRegistry.values()
is deprecated and will be removed in a future version of ClassRegistry. UseBaseRegistry.classes()
instead.BaseRegistry.items()
is deprecated and will be removed in a future version of ClassRegistry. Usezip(registry.keys(), registry.classes())
instead.Major changes
ClassRegistry
now accepts an optional type parameter, to indicate the type of objects that it can create. Example:ClassRegistryInstanceCache
now accepts an optional type parameter, or infers it from theClassRegistry
that it wraps. Example:Minor changes
ClassRegistryInstanceCache
now extendstyping.Mapping
.ClassRegistryInstanceCache.__len__()
.BaseRegistry.__len__()
is no longer abstract.