mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-21 08:02:07 -04:00
Removed new protocols from sqlalchemy.orm
This commit is contained in:
@@ -578,27 +578,24 @@ from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import NoReturn
|
||||
from typing import Optional
|
||||
from typing import Tuple
|
||||
from typing import Type
|
||||
from typing import TypeVar
|
||||
from typing import Union
|
||||
|
||||
from mypy_extensions import NoReturn
|
||||
|
||||
from .. import util
|
||||
from ..engine.base import Engine
|
||||
from ..orm import backref
|
||||
from ..orm import BackrefConstructorType
|
||||
from ..orm import declarative_base as _declarative_base
|
||||
from ..orm import exc as orm_exc
|
||||
from ..orm import interfaces
|
||||
from ..orm import RelaionshipConstructorType
|
||||
from ..orm import relationship
|
||||
from ..orm.base import RelationshipDirection
|
||||
from ..orm.decl_base import _DeferredMapperConfig
|
||||
from ..orm.mapper import _CONFIGURE_MUTEX
|
||||
from ..orm.relationships import _ORMBackrefArgument
|
||||
from ..orm.relationships import ORMBackrefArgument
|
||||
from ..orm.relationships import Relationship
|
||||
from ..schema import ForeignKeyConstraint
|
||||
from ..sql import and_
|
||||
@@ -607,7 +604,6 @@ from ..sql.schema import Column
|
||||
from ..sql.schema import Table
|
||||
from ..util._py_collections import immutabledict
|
||||
from ..util.typing import Protocol
|
||||
from ..util.typing import TypeGuard
|
||||
|
||||
_KT = TypeVar("_KT", bound=Any)
|
||||
_VT = TypeVar("_VT", bound=Any)
|
||||
@@ -745,24 +741,24 @@ class GenerateRelationshipType(Protocol):
|
||||
self,
|
||||
base: Type[Any],
|
||||
direction: RelationshipDirection,
|
||||
return_fn: BackrefConstructorType | RelaionshipConstructorType,
|
||||
return_fn: Callable[..., Union[Relationship[Any], ORMBackrefArgument]],
|
||||
attrname: str,
|
||||
local_cls: Type[Any],
|
||||
referred_cls: Type[Any],
|
||||
**kw: Any,
|
||||
) -> _ORMBackrefArgument | Relationship[Any]:
|
||||
) -> Union[ORMBackrefArgument, Relationship[Any]]:
|
||||
...
|
||||
|
||||
|
||||
def generate_relationship(
|
||||
base: Type[Any],
|
||||
direction: RelationshipDirection,
|
||||
return_fn: BackrefConstructorType | RelaionshipConstructorType,
|
||||
return_fn: Callable[..., Union[Relationship[Any], ORMBackrefArgument]],
|
||||
attrname: str,
|
||||
local_cls: Type[Any],
|
||||
referred_cls: Type[Any],
|
||||
**kw: Any,
|
||||
) -> _ORMBackrefArgument | Relationship[Any]:
|
||||
) -> Union[ORMBackrefArgument, Relationship[Any]]:
|
||||
r"""Generate a :func:`_orm.relationship` or :func:`.backref`
|
||||
on behalf of two
|
||||
mapped classes.
|
||||
@@ -812,19 +808,9 @@ def generate_relationship(
|
||||
|
||||
"""
|
||||
|
||||
def is_backref(
|
||||
func: Callable[..., Any]
|
||||
) -> TypeGuard[BackrefConstructorType]:
|
||||
return func is backref
|
||||
|
||||
def is_relationship(
|
||||
func: Callable[..., Any]
|
||||
) -> TypeGuard[RelaionshipConstructorType]:
|
||||
return func is relationship
|
||||
|
||||
if is_backref(return_fn):
|
||||
if return_fn is backref:
|
||||
return return_fn(attrname, **kw)
|
||||
elif is_relationship(return_fn):
|
||||
elif return_fn is relationship:
|
||||
return return_fn(referred_cls, **kw)
|
||||
else:
|
||||
raise TypeError("Unknown relationship function: %s" % return_fn)
|
||||
@@ -1196,7 +1182,7 @@ def _relationships_for_fks(
|
||||
automap_base, referred_cls, local_cls, constraint
|
||||
)
|
||||
|
||||
o2m_kws: dict[str, str | bool] = {}
|
||||
o2m_kws: dict[str, Union[str, bool]] = {}
|
||||
nullable = False not in {fk.parent.nullable for fk in fks}
|
||||
if not nullable:
|
||||
o2m_kws["cascade"] = "all, delete-orphan"
|
||||
|
||||
@@ -23,9 +23,6 @@ from . import strategy_options as strategy_options
|
||||
from ._orm_constructors import _mapper_fn as mapper
|
||||
from ._orm_constructors import aliased as aliased
|
||||
from ._orm_constructors import backref as backref
|
||||
from ._orm_constructors import (
|
||||
BackrefConstructorType as BackrefConstructorType,
|
||||
)
|
||||
from ._orm_constructors import clear_mappers as clear_mappers
|
||||
from ._orm_constructors import column_property as column_property
|
||||
from ._orm_constructors import composite as composite
|
||||
@@ -37,9 +34,6 @@ from ._orm_constructors import join as join
|
||||
from ._orm_constructors import mapped_column as mapped_column
|
||||
from ._orm_constructors import outerjoin as outerjoin
|
||||
from ._orm_constructors import query_expression as query_expression
|
||||
from ._orm_constructors import (
|
||||
RelaionshipConstructorType as RelaionshipConstructorType,
|
||||
)
|
||||
from ._orm_constructors import relationship as relationship
|
||||
from ._orm_constructors import synonym as synonym
|
||||
from ._orm_constructors import with_loader_criteria as with_loader_criteria
|
||||
|
||||
@@ -46,7 +46,6 @@ from ..sql.schema import SchemaConst
|
||||
from ..sql.selectable import FromClause
|
||||
from ..util.typing import Annotated
|
||||
from ..util.typing import Literal
|
||||
from ..util.typing import Protocol
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._typing import _EntityType
|
||||
@@ -57,10 +56,10 @@ if TYPE_CHECKING:
|
||||
from .mapper import Mapper
|
||||
from .query import Query
|
||||
from .relationships import _LazyLoadArgumentType
|
||||
from .relationships import _ORMBackrefArgument
|
||||
from .relationships import _ORMColCollectionArgument
|
||||
from .relationships import _ORMOrderByArgument
|
||||
from .relationships import _RelationshipJoinConditionArgument
|
||||
from .relationships import ORMBackrefArgument
|
||||
from .session import _SessionBind
|
||||
from ..sql._typing import _ColumnExpressionArgument
|
||||
from ..sql._typing import _FromClauseArgument
|
||||
@@ -735,54 +734,6 @@ def with_loader_criteria(
|
||||
)
|
||||
|
||||
|
||||
class RelaionshipConstructorType(Protocol):
|
||||
def __call__(
|
||||
self,
|
||||
argument: Optional[_RelationshipArgumentType[Any]] = None,
|
||||
secondary: Optional[Union[FromClause, str]] = None,
|
||||
*,
|
||||
uselist: Optional[bool] = None,
|
||||
collection_class: Optional[
|
||||
Union[Type[Collection[Any]], Callable[[], Collection[Any]]]
|
||||
] = None,
|
||||
primaryjoin: Optional[_RelationshipJoinConditionArgument] = None,
|
||||
secondaryjoin: Optional[_RelationshipJoinConditionArgument] = None,
|
||||
back_populates: Optional[str] = None,
|
||||
order_by: _ORMOrderByArgument = False,
|
||||
backref: Optional[_ORMBackrefArgument] = None,
|
||||
overlaps: Optional[str] = None,
|
||||
post_update: bool = False,
|
||||
cascade: str = "save-update, merge",
|
||||
viewonly: bool = False,
|
||||
init: Union[_NoArg, bool] = _NoArg.NO_ARG,
|
||||
repr: Union[_NoArg, bool] = _NoArg.NO_ARG, # noqa: A002
|
||||
default: Union[_NoArg, _T] = _NoArg.NO_ARG,
|
||||
default_factory: Union[_NoArg, Callable[[], _T]] = _NoArg.NO_ARG,
|
||||
kw_only: Union[_NoArg, bool] = _NoArg.NO_ARG,
|
||||
lazy: _LazyLoadArgumentType = "select",
|
||||
passive_deletes: Union[Literal["all"], bool] = False,
|
||||
passive_updates: bool = True,
|
||||
active_history: bool = False,
|
||||
enable_typechecks: bool = True,
|
||||
foreign_keys: Optional[_ORMColCollectionArgument] = None,
|
||||
remote_side: Optional[_ORMColCollectionArgument] = None,
|
||||
join_depth: Optional[int] = None,
|
||||
comparator_factory: Optional[
|
||||
Type[RelationshipProperty.Comparator[Any]]
|
||||
] = None,
|
||||
single_parent: bool = False,
|
||||
innerjoin: bool = False,
|
||||
distinct_target_key: Optional[bool] = None,
|
||||
load_on_pending: bool = False,
|
||||
query_class: Optional[Type[Query[Any]]] = None,
|
||||
info: Optional[_InfoType] = None,
|
||||
omit_join: Literal[None, False] = None,
|
||||
sync_backref: Optional[bool] = None,
|
||||
**kw: Any,
|
||||
) -> Relationship[Any]:
|
||||
...
|
||||
|
||||
|
||||
def relationship(
|
||||
argument: Optional[_RelationshipArgumentType[Any]] = None,
|
||||
secondary: Optional[Union[FromClause, str]] = None,
|
||||
@@ -795,7 +746,7 @@ def relationship(
|
||||
secondaryjoin: Optional[_RelationshipJoinConditionArgument] = None,
|
||||
back_populates: Optional[str] = None,
|
||||
order_by: _ORMOrderByArgument = False,
|
||||
backref: Optional[_ORMBackrefArgument] = None,
|
||||
backref: Optional[ORMBackrefArgument] = None,
|
||||
overlaps: Optional[str] = None,
|
||||
post_update: bool = False,
|
||||
cascade: str = "save-update, merge",
|
||||
@@ -1903,12 +1854,7 @@ def dynamic_loader(
|
||||
return relationship(argument, **kw)
|
||||
|
||||
|
||||
class BackrefConstructorType(Protocol):
|
||||
def __call__(self, name: str, **kwargs: Any) -> _ORMBackrefArgument:
|
||||
...
|
||||
|
||||
|
||||
def backref(name: str, **kwargs: Any) -> _ORMBackrefArgument:
|
||||
def backref(name: str, **kwargs: Any) -> ORMBackrefArgument:
|
||||
"""When using the :paramref:`_orm.relationship.backref` parameter,
|
||||
provides specific parameters to be used when the new
|
||||
:func:`_orm.relationship` is generated.
|
||||
|
||||
@@ -167,7 +167,7 @@ _ORMOrderByArgument = Union[
|
||||
Callable[[], Iterable[ColumnElement[Any]]],
|
||||
Iterable[Union[str, _ColumnExpressionArgument[Any]]],
|
||||
]
|
||||
_ORMBackrefArgument = Union[str, Tuple[str, Dict[str, Any]]]
|
||||
ORMBackrefArgument = Union[str, Tuple[str, Dict[str, Any]]]
|
||||
|
||||
_ORMColCollectionElement = Union[
|
||||
ColumnClause[Any], _HasClauseElement, roles.DMLColumnRole
|
||||
@@ -362,7 +362,7 @@ class RelationshipProperty(
|
||||
secondaryjoin: Optional[_RelationshipJoinConditionArgument] = None,
|
||||
back_populates: Optional[str] = None,
|
||||
order_by: _ORMOrderByArgument = False,
|
||||
backref: Optional[_ORMBackrefArgument] = None,
|
||||
backref: Optional[ORMBackrefArgument] = None,
|
||||
overlaps: Optional[str] = None,
|
||||
post_update: bool = False,
|
||||
cascade: str = "save-update, merge",
|
||||
|
||||
Reference in New Issue
Block a user