summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/clsregistry.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-09-29 12:56:23 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-10-05 20:35:57 -0400
commit566cccc8645be99a23811c39d43481d7248628b0 (patch)
tree15bad7e506967108c0f2e8aec626e8eebd6ff1fc /lib/sqlalchemy/orm/clsregistry.py
parent3ab59694dbe04bf967e9af18d1ae49e1c5ea44ed (diff)
downloadsqlalchemy-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/clsregistry.py')
-rw-r--r--lib/sqlalchemy/orm/clsregistry.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/clsregistry.py b/lib/sqlalchemy/orm/clsregistry.py
index dd79eb1d0..99a51c998 100644
--- a/lib/sqlalchemy/orm/clsregistry.py
+++ b/lib/sqlalchemy/orm/clsregistry.py
@@ -36,7 +36,7 @@ import weakref
from . import attributes
from . import interfaces
-from .descriptor_props import Synonym
+from .descriptor_props import SynonymProperty
from .properties import ColumnProperty
from .util import class_mapper
from .. import exc
@@ -46,7 +46,7 @@ from ..sql.schema import _get_table_key
from ..util.typing import CallableReference
if TYPE_CHECKING:
- from .relationships import Relationship
+ from .relationships import RelationshipProperty
from ..sql.schema import MetaData
from ..sql.schema import Table
@@ -350,7 +350,7 @@ class _GetColumns:
if desc.extension_type is interfaces.NotExtension.NOT_EXTENSION:
assert isinstance(desc, attributes.QueryableAttribute)
prop = desc.property
- if isinstance(prop, Synonym):
+ if isinstance(prop, SynonymProperty):
key = prop.name
elif not isinstance(prop, ColumnProperty):
raise exc.InvalidRequestError(
@@ -398,7 +398,7 @@ class _class_resolver:
)
cls: Type[Any]
- prop: Relationship[Any]
+ prop: RelationshipProperty[Any]
fallback: Mapping[str, Any]
arg: str
favor_tables: bool
@@ -407,7 +407,7 @@ class _class_resolver:
def __init__(
self,
cls: Type[Any],
- prop: Relationship[Any],
+ prop: RelationshipProperty[Any],
fallback: Mapping[str, Any],
arg: str,
favor_tables: bool = False,
@@ -520,7 +520,7 @@ _fallback_dict: Mapping[str, Any] = None # type: ignore
def _resolver(
- cls: Type[Any], prop: Relationship[Any]
+ cls: Type[Any], prop: RelationshipProperty[Any]
) -> Tuple[
Callable[[str], Callable[[], Union[Type[Any], Table, _ModNS]]],
Callable[[str, bool], _class_resolver],