main commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-16 16:30:25 +09:00
parent 91c7e04474
commit 537e7b363f
1146 changed files with 45926 additions and 77196 deletions

View File

@@ -1,11 +1,13 @@
# orm/base.py
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: https://www.opensource.org/licenses/mit-license.php
"""Constants and rudimental functions used throughout the ORM."""
"""Constants and rudimental functions used throughout the ORM.
"""
from __future__ import annotations
@@ -19,7 +21,6 @@ from typing import Generic
from typing import no_type_check
from typing import Optional
from typing import overload
from typing import Tuple
from typing import Type
from typing import TYPE_CHECKING
from typing import TypeVar
@@ -143,7 +144,7 @@ class PassiveFlag(FastIntFlag):
"""
NO_AUTOFLUSH = 64
"""Loader callables should disable autoflush."""
"""Loader callables should disable autoflush.""",
NO_RAISE = 128
"""Loader callables should not raise any assertions"""
@@ -281,8 +282,6 @@ _never_set = frozenset([NEVER_SET])
_none_set = frozenset([None, NEVER_SET, PASSIVE_NO_RESULT])
_none_only_set = frozenset([None])
_SET_DEFERRED_EXPIRED = util.symbol("SET_DEFERRED_EXPIRED")
_DEFER_FOR_STATE = util.symbol("DEFER_FOR_STATE")
@@ -309,23 +308,29 @@ def _assertions(
if TYPE_CHECKING:
def manager_of_class(cls: Type[_O]) -> ClassManager[_O]: ...
def manager_of_class(cls: Type[_O]) -> ClassManager[_O]:
...
@overload
def opt_manager_of_class(cls: AliasedClass[Any]) -> None: ...
def opt_manager_of_class(cls: AliasedClass[Any]) -> None:
...
@overload
def opt_manager_of_class(
cls: _ExternalEntityType[_O],
) -> Optional[ClassManager[_O]]: ...
) -> Optional[ClassManager[_O]]:
...
def opt_manager_of_class(
cls: _ExternalEntityType[_O],
) -> Optional[ClassManager[_O]]: ...
) -> Optional[ClassManager[_O]]:
...
def instance_state(instance: _O) -> InstanceState[_O]: ...
def instance_state(instance: _O) -> InstanceState[_O]:
...
def instance_dict(instance: object) -> Dict[str, Any]: ...
def instance_dict(instance: object) -> Dict[str, Any]:
...
else:
# these can be replaced by sqlalchemy.ext.instrumentation
@@ -433,7 +438,7 @@ def _inspect_mapped_object(instance: _T) -> Optional[InstanceState[_T]]:
def _class_to_mapper(
class_or_mapper: Union[Mapper[_T], Type[_T]],
class_or_mapper: Union[Mapper[_T], Type[_T]]
) -> Mapper[_T]:
# can't get mypy to see an overload for this
insp = inspection.inspect(class_or_mapper, False)
@@ -445,7 +450,7 @@ def _class_to_mapper(
def _mapper_or_none(
entity: Union[Type[_T], _InternalEntityType[_T]],
entity: Union[Type[_T], _InternalEntityType[_T]]
) -> Optional[Mapper[_T]]:
"""Return the :class:`_orm.Mapper` for the given class or None if the
class is not mapped.
@@ -507,7 +512,8 @@ def _entity_descriptor(entity: _EntityType[Any], key: str) -> Any:
if TYPE_CHECKING:
def _state_mapper(state: InstanceState[_O]) -> Mapper[_O]: ...
def _state_mapper(state: InstanceState[_O]) -> Mapper[_O]:
...
else:
_state_mapper = util.dottedgetter("manager.mapper")
@@ -580,7 +586,7 @@ class InspectionAttr:
"""
__slots__: Tuple[str, ...] = ()
__slots__ = ()
is_selectable = False
"""Return True if this object is an instance of
@@ -678,25 +684,27 @@ class SQLORMOperations(SQLCoreOperations[_T_co], TypingOnly):
if typing.TYPE_CHECKING:
def of_type(
self, class_: _EntityType[Any]
) -> PropComparator[_T_co]: ...
def of_type(self, class_: _EntityType[Any]) -> PropComparator[_T_co]:
...
def and_(
self, *criteria: _ColumnExpressionArgument[bool]
) -> PropComparator[bool]: ...
) -> PropComparator[bool]:
...
def any( # noqa: A001
self,
criterion: Optional[_ColumnExpressionArgument[bool]] = None,
**kwargs: Any,
) -> ColumnElement[bool]: ...
) -> ColumnElement[bool]:
...
def has(
self,
criterion: Optional[_ColumnExpressionArgument[bool]] = None,
**kwargs: Any,
) -> ColumnElement[bool]: ...
) -> ColumnElement[bool]:
...
class ORMDescriptor(Generic[_T_co], TypingOnly):
@@ -710,19 +718,23 @@ class ORMDescriptor(Generic[_T_co], TypingOnly):
@overload
def __get__(
self, instance: Any, owner: Literal[None]
) -> ORMDescriptor[_T_co]: ...
) -> ORMDescriptor[_T_co]:
...
@overload
def __get__(
self, instance: Literal[None], owner: Any
) -> SQLCoreOperations[_T_co]: ...
) -> SQLCoreOperations[_T_co]:
...
@overload
def __get__(self, instance: object, owner: Any) -> _T_co: ...
def __get__(self, instance: object, owner: Any) -> _T_co:
...
def __get__(
self, instance: object, owner: Any
) -> Union[ORMDescriptor[_T_co], SQLCoreOperations[_T_co], _T_co]: ...
) -> Union[ORMDescriptor[_T_co], SQLCoreOperations[_T_co], _T_co]:
...
class _MappedAnnotationBase(Generic[_T_co], TypingOnly):
@@ -808,23 +820,29 @@ class Mapped(
@overload
def __get__(
self, instance: None, owner: Any
) -> InstrumentedAttribute[_T_co]: ...
) -> InstrumentedAttribute[_T_co]:
...
@overload
def __get__(self, instance: object, owner: Any) -> _T_co: ...
def __get__(self, instance: object, owner: Any) -> _T_co:
...
def __get__(
self, instance: Optional[object], owner: Any
) -> Union[InstrumentedAttribute[_T_co], _T_co]: ...
) -> Union[InstrumentedAttribute[_T_co], _T_co]:
...
@classmethod
def _empty_constructor(cls, arg1: Any) -> Mapped[_T_co]: ...
def _empty_constructor(cls, arg1: Any) -> Mapped[_T_co]:
...
def __set__(
self, instance: Any, value: Union[SQLCoreOperations[_T_co], _T_co]
) -> None: ...
) -> None:
...
def __delete__(self, instance: Any) -> None: ...
def __delete__(self, instance: Any) -> None:
...
class _MappedAttribute(Generic[_T_co], TypingOnly):
@@ -901,20 +919,24 @@ class DynamicMapped(_MappedAnnotationBase[_T_co]):
@overload
def __get__(
self, instance: None, owner: Any
) -> InstrumentedAttribute[_T_co]: ...
) -> InstrumentedAttribute[_T_co]:
...
@overload
def __get__(
self, instance: object, owner: Any
) -> AppenderQuery[_T_co]: ...
) -> AppenderQuery[_T_co]:
...
def __get__(
self, instance: Optional[object], owner: Any
) -> Union[InstrumentedAttribute[_T_co], AppenderQuery[_T_co]]: ...
) -> Union[InstrumentedAttribute[_T_co], AppenderQuery[_T_co]]:
...
def __set__(
self, instance: Any, value: typing.Collection[_T_co]
) -> None: ...
) -> None:
...
class WriteOnlyMapped(_MappedAnnotationBase[_T_co]):
@@ -953,19 +975,21 @@ class WriteOnlyMapped(_MappedAnnotationBase[_T_co]):
@overload
def __get__(
self, instance: None, owner: Any
) -> InstrumentedAttribute[_T_co]: ...
) -> InstrumentedAttribute[_T_co]:
...
@overload
def __get__(
self, instance: object, owner: Any
) -> WriteOnlyCollection[_T_co]: ...
) -> WriteOnlyCollection[_T_co]:
...
def __get__(
self, instance: Optional[object], owner: Any
) -> Union[
InstrumentedAttribute[_T_co], WriteOnlyCollection[_T_co]
]: ...
) -> Union[InstrumentedAttribute[_T_co], WriteOnlyCollection[_T_co]]:
...
def __set__(
self, instance: Any, value: typing.Collection[_T_co]
) -> None: ...
) -> None:
...