diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-01-10 16:48:05 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-01-11 13:06:57 -0500 |
| commit | 3a23e8ed29180e914883a263ec83373ecbd02efa (patch) | |
| tree | 30775bf16114d0415d1b429dc4df1957e64cf082 /lib/sqlalchemy/testing/fixtures.py | |
| parent | 5681d4e4da8ee69d83e9c0103c171d413d4c183e (diff) | |
| download | sqlalchemy-3a23e8ed29180e914883a263ec83373ecbd02efa.tar.gz | |
remove internal use of metaclasses
All but one metaclass used internally can now
be replaced using __init_subclass__(). Within this
patch we remove:
* events._EventMeta
* sql.visitors.TraversibleType
* sql.visitors.InternalTraversibleType
* testing.fixtures.FindFixture
* testing.fixtures.FindFixtureDeclarative
* langhelpers.EnsureKWArgType
* sql.functions._GenericMeta
* sql.type_api.VisitableCheckKWArg (was a mixture of TraversibleType
and EnsureKWArgType)
The remaining internal class is MetaOptions used by the
sql.Options object which is in turn currently mostly for
ORM internal use, as this type implements class level overrides
for the ``+`` operator.
For declarative, removing DeclarativeMeta in place of
an `__init_subclass__()` class would not be fully feasible as
it would break backwards compatibility with applications that
refer to this class explicitly, but also DeclarativeMeta intercepts
class-level attribute set and delete operations which is a widely
used pattern. An option for declarative base to use
`__init_subclass__()` should be provided but this is out of
scope for this particular change.
Change-Id: I8aa898c7ab59d887739037d34b1cbab36521ab78
References: #6810
Diffstat (limited to 'lib/sqlalchemy/testing/fixtures.py')
| -rw-r--r-- | lib/sqlalchemy/testing/fixtures.py | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py index 74c86e85a..ecc20f163 100644 --- a/lib/sqlalchemy/testing/fixtures.py +++ b/lib/sqlalchemy/testing/fixtures.py @@ -21,7 +21,6 @@ from .. import event from .. import util from ..orm import declarative_base from ..orm import registry -from ..orm.decl_api import DeclarativeMeta from ..schema import sort_tables_and_constraints @@ -647,15 +646,11 @@ class MappedTest(TablesTest, assertions.AssertsExecutionResults): """ cls_registry = cls.classes - assert cls_registry is not None - - class FindFixture(type): - def __init__(cls, classname, bases, dict_): - cls_registry[classname] = cls - type.__init__(cls, classname, bases, dict_) - - class _Base(metaclass=FindFixture): - pass + class _Base: + def __init_subclass__(cls) -> None: + assert cls_registry is not None + cls_registry[cls.__name__] = cls + super().__init_subclass__() class Basic(BasicEntity, _Base): pass @@ -699,17 +694,16 @@ class DeclarativeMappedTest(MappedTest): def _with_register_classes(cls, fn): cls_registry = cls.classes - class FindFixtureDeclarative(DeclarativeMeta): - def __init__(cls, classname, bases, dict_): - cls_registry[classname] = cls - DeclarativeMeta.__init__(cls, classname, bases, dict_) - class DeclarativeBasic: __table_cls__ = schema.Table + def __init_subclass__(cls) -> None: + assert cls_registry is not None + cls_registry[cls.__name__] = cls + super().__init_subclass__() + _DeclBase = declarative_base( metadata=cls._tables_metadata, - metaclass=FindFixtureDeclarative, cls=DeclarativeBasic, ) |
