⚠️ This version contains changes that are not backwards-compatible! Refer to Upgrading to ClassRegistry v5 for migration instructions. ⚠️
If you have any questions, or if you run into any issues, drop a note on the ClassRegistry issue tracker, and I'll get you sorted 😺
Breaking changes
Cleaned up top-level class_registry namespace. Refer to Upgrading to ClassRegistry v5 for instructions to update your import statements.
class_registry.AutoRegister is deprecated in favour of class_registry.base.AutoRegister which returns a base class instead of a metaclass:
ClassRegistry v4.x:
from class_registry import AutoRegister
class MyBaseClass(metaclass=AutoRegister(registry)):
...
ClassRegistry v5.x:
from abc import ABC
from class_registry.base import AutoRegister
class MyBaseClass(AutoRegister(registry), ABC):
...
BaseRegistry no longer implements typing.Mapping, due to violations of the Liskov Substitution Principle.
Removed BaseRegistry.items().
Renamed BaseRegistry.values() to BaseRegistry.classes().
BaseMutableRegistry no longer implements typing.MutableMapping, due to violations of the Liskov Substitution Principle.
Removed BaseMutableRegistry.__delitem__().
Removed BaseMutableRegistry.__setitem__().
Removed EntryPointClassRegistry.items() for consistency with BaseRegistry.
New functionality
If a ClassRegistry instance always returns objects derived from a particular base class, you can now provide a type parameter to help with type checking, autocomplete, etc.:
# Add type parameter ``[Pokemon]``:
pokedex = ClassRegistry[Pokemon]()
# Your IDE will automatically infer that ``fighter1`` is a ``Pokemon``.
fighter1 = pokedex['fire']
ClassRegistryInstanceCache inherits the type parameter from its wrapped ClassRegistry instance, or you can specify it explicitly:
# Add type parameter ``[Pokemon]``:
registry = ClassRegistry[Pokemon]()
# The ``ClassRegistryInstanceCache`` inherits the type parameters from the
# ``ClassRegistry`` that it wraps.
pokedex = ClassRegistryInstanceCache(registry)
# Your IDE will automatically infer that ``fire_fighter`` is a ``Pokemon``.
fire_fighter = pokedex['fire']
Added BaseRegistry.__dir__().
Added BaseRegistry.__len__().
Other changes
Fixed an error when checking if a class is registered when that class' initialiser requires at least one argument.
Rewrote tests to be easier to read.
Now uses Poetry for packaging and dependency management.
Integrated black into CI pipeline and pre-commit hook.
Integrated mypy into CI pipeline and pre-commit hook.
Integrated ruff into CI pipeline and pre-commit hook.
⚠️ This version contains changes that are not backwards-compatible! Refer to Upgrading to ClassRegistry v5 for migration instructions. ⚠️
If you have any questions, or if you run into any issues, drop a note on the ClassRegistry issue tracker, and I'll get you sorted 😺
Breaking changes
class_registry
namespace. Refer to Upgrading to ClassRegistry v5 for instructions to update yourimport
statements.class_registry.AutoRegister
is deprecated in favour ofclass_registry.base.AutoRegister
which returns a base class instead of a metaclass:ClassRegistry v4.x:
ClassRegistry v5.x:
BaseRegistry
no longer implementstyping.Mapping
, due to violations of the Liskov Substitution Principle.BaseRegistry.items()
.BaseRegistry.values()
toBaseRegistry.classes()
.BaseMutableRegistry
no longer implementstyping.MutableMapping
, due to violations of the Liskov Substitution Principle.BaseMutableRegistry.__delitem__()
.BaseMutableRegistry.__setitem__()
.EntryPointClassRegistry.items()
for consistency withBaseRegistry
.New functionality
If a
ClassRegistry
instance always returns objects derived from a particular base class, you can now provide a type parameter to help with type checking, autocomplete, etc.:ClassRegistryInstanceCache
inherits the type parameter from its wrappedClassRegistry
instance, or you can specify it explicitly:Added
BaseRegistry.__dir__()
.Added
BaseRegistry.__len__()
.Other changes