if TYPE_CHECKING:
from ._typing import _InternalEntityType
- from .interfaces import MapperProperty
+ from .interfaces import StrategizedProperty
from .mapper import Mapper
from .relationships import RelationshipProperty
from .util import AliasedInsp
_SerializedPath = List[Any]
_StrPathToken = str
_PathElementType = Union[
- _StrPathToken, "_InternalEntityType[Any]", "MapperProperty[Any]"
+ _StrPathToken, "_InternalEntityType[Any]", "StrategizedProperty[Any]"
]
# the representation is in fact
# a tuple with alternating:
-# [_InternalEntityType[Any], Union[str, MapperProperty[Any]],
-# _InternalEntityType[Any], Union[str, MapperProperty[Any]], ...]
+# [_InternalEntityType[Any], Union[str, StrategizedProperty[Any]],
+# _InternalEntityType[Any], Union[str, StrategizedProperty[Any]], ...]
# this might someday be a tuple of 2-tuples instead, but paths can be
# chopped at odd intervals as well so this is less flexible
_PathRepresentation = Tuple[_PathElementType, ...]
# NOTE: these names are weird since the array is 0-indexed,
# the "_Odd" entries are at 0, 2, 4, etc
_OddPathRepresentation = Sequence["_InternalEntityType[Any]"]
-_EvenPathRepresentation = Sequence[Union["MapperProperty[Any]", str]]
+_EvenPathRepresentation = Sequence[Union["StrategizedProperty[Any]", str]]
log = logging.getLogger(__name__)
) -> AbstractEntityRegistry: ...
@overload
- def __getitem__(self, entity: MapperProperty[Any]) -> PropRegistry: ...
+ def __getitem__(
+ self, entity: StrategizedProperty[Any]
+ ) -> PropRegistry: ...
def __getitem__(
self,
int,
slice,
_InternalEntityType[Any],
- MapperProperty[Any],
+ StrategizedProperty[Any],
],
) -> Union[
TokenRegistry,
def pairs(
self,
) -> Iterator[
- Tuple[_InternalEntityType[Any], Union[str, MapperProperty[Any]]]
+ Tuple[_InternalEntityType[Any], Union[str, StrategizedProperty[Any]]]
]:
odd_path = cast(_OddPathRepresentation, self.path)
even_path = cast(_EvenPathRepresentation, odd_path)
inherit_cache = True
is_property = True
- prop: MapperProperty[Any]
+ prop: StrategizedProperty[Any]
mapper: Optional[Mapper[Any]]
entity: Optional[_InternalEntityType[Any]]
def __init__(
- self, parent: AbstractEntityRegistry, prop: MapperProperty[Any]
+ self, parent: AbstractEntityRegistry, prop: StrategizedProperty[Any]
):
+
# restate this path in terms of the
- # given MapperProperty's parent.
+ # given StrategizedProperty's parent.
insp = cast("_InternalEntityType[Any]", parent[-1])
natural_parent: AbstractEntityRegistry = parent
class CompositeAttributesTest(fixtures.TestBase):
- @testing.fixture
- def mapping_fixture(self, registry, connection):
- Base = registry.generate_base()
- class BaseCls(Base):
- __tablename__ = "base"
- id = Column(
- Integer, primary_key=True, test_needs_autoincrement=True
- )
- type = Column(String(50))
-
- __mapper_args__ = {"polymorphic_on": type}
+ @testing.fixture(params=("base", "sub"))
+ def mapping_fixture(self, request, registry, connection):
+ Base = registry.generate_base()
class XYThing:
def __init__(self, x, y):
def __ne__(self, other):
return not self.__eq__(other)
+ class BaseCls(Base):
+ __tablename__ = "base"
+ id = Column(
+ Integer, primary_key=True, test_needs_autoincrement=True
+ )
+ type = Column(String(50))
+
+ if request.param == "base":
+ comp1 = composite(
+ XYThing, Column("x1", Integer), Column("y1", Integer)
+ )
+
+ __mapper_args__ = {"polymorphic_on": type}
+
class A(ComparableEntity, BaseCls):
__tablename__ = "a"
id = Column(ForeignKey(BaseCls.id), primary_key=True)
thing1 = Column(String(50))
- comp1 = composite(
- XYThing, Column("x1", Integer), Column("y1", Integer)
- )
+ if request.param == "sub":
+ comp1 = composite(
+ XYThing, Column("x1", Integer), Column("y1", Integer)
+ )
__mapper_args__ = {
"polymorphic_identity": "a",