diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-09-29 12:56:23 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-10-05 20:35:57 -0400 |
commit | 566cccc8645be99a23811c39d43481d7248628b0 (patch) | |
tree | 15bad7e506967108c0f2e8aec626e8eebd6ff1fc /lib/sqlalchemy/orm/mapper.py | |
parent | 3ab59694dbe04bf967e9af18d1ae49e1c5ea44ed (diff) | |
download | sqlalchemy-566cccc8645be99a23811c39d43481d7248628b0.tar.gz |
reorganize Mapped[] super outside of MapperProperty
We made all the MapperProperty classes a subclass
of Mapped[] to allow declarative mappings to name
Mapped[] on the left side. this was cheating a bit because
MapperProperty is not actually a descriptor, and the mapping
process replaces the object with InstrumentedAttribute at
mapping time, which is the actual Mapped[] descriptor.
But now in I6929f3da6e441cad92285e7309030a9bac4e429d we
are considering making the "cheating" a little more extensive
by putting DynamicMapped / WriteOnlyMapped in Relationship's
hierarchy, which need a flat out "type: ignore" to work.
Instead of pushing more cheats into the core classes, move
out the "Declarative"-facing versions of these classes to be
typing only: Relationship, Composite, Synonym, and MappedSQLExpression
added for ColumnProperty. Keep the internals expressed on the
old names, RelationshipProperty, CompositeProperty, SynonymProperty,
ColumnProprerty, which will remain "pure" with fully correct typing.
then have the typing only endpoints be where the "cheating"
and "type: ignores" have to happen, so that these are more or less
slightly better forms of "Any".
Change-Id: Ied7cc11196c9204da6851f49593d1b1fd2ef8ad8
Diffstat (limited to 'lib/sqlalchemy/orm/mapper.py')
-rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 553f7b35b..36b97cf17 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -95,13 +95,13 @@ if TYPE_CHECKING: from ._typing import _RegistryType from .decl_api import registry from .dependency import DependencyProcessor - from .descriptor_props import Composite - from .descriptor_props import Synonym + from .descriptor_props import CompositeProperty + from .descriptor_props import SynonymProperty from .events import MapperEvents from .instrumentation import ClassManager from .path_registry import CachingEntityRegistry from .properties import ColumnProperty - from .relationships import Relationship + from .relationships import RelationshipProperty from .state import InstanceState from ..engine import Row from ..engine import RowMapping @@ -2782,7 +2782,7 @@ class Mapper( @HasMemoized.memoized_attribute @util.preload_module("sqlalchemy.orm.descriptor_props") - def synonyms(self) -> util.ReadOnlyProperties[Synonym[Any]]: + def synonyms(self) -> util.ReadOnlyProperties[SynonymProperty[Any]]: """Return a namespace of all :class:`.Synonym` properties maintained by this :class:`_orm.Mapper`. @@ -2795,7 +2795,7 @@ class Mapper( """ descriptor_props = util.preloaded.orm_descriptor_props - return self._filter_properties(descriptor_props.Synonym) + return self._filter_properties(descriptor_props.SynonymProperty) @property def entity_namespace(self): @@ -2817,7 +2817,9 @@ class Mapper( @HasMemoized.memoized_attribute @util.preload_module("sqlalchemy.orm.relationships") - def relationships(self) -> util.ReadOnlyProperties[Relationship[Any]]: + def relationships( + self, + ) -> util.ReadOnlyProperties[RelationshipProperty[Any]]: """A namespace of all :class:`.Relationship` properties maintained by this :class:`_orm.Mapper`. @@ -2841,12 +2843,12 @@ class Mapper( """ return self._filter_properties( - util.preloaded.orm_relationships.Relationship + util.preloaded.orm_relationships.RelationshipProperty ) @HasMemoized.memoized_attribute @util.preload_module("sqlalchemy.orm.descriptor_props") - def composites(self) -> util.ReadOnlyProperties[Composite[Any]]: + def composites(self) -> util.ReadOnlyProperties[CompositeProperty[Any]]: """Return a namespace of all :class:`.Composite` properties maintained by this :class:`_orm.Mapper`. @@ -2858,7 +2860,7 @@ class Mapper( """ return self._filter_properties( - util.preloaded.orm_descriptor_props.Composite + util.preloaded.orm_descriptor_props.CompositeProperty ) def _filter_properties( |