API refactor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-07 16:25:52 +09:00
parent 76d0d86211
commit 91c7e04474
1171 changed files with 81940 additions and 44117 deletions

View File

@@ -1,5 +1,5 @@
# orm/scoping.py
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
@@ -86,8 +86,7 @@ class QueryPropertyDescriptor(Protocol):
"""
def __get__(self, instance: Any, owner: Type[_T]) -> Query[_T]:
...
def __get__(self, instance: Any, owner: Type[_T]) -> Query[_T]: ...
_O = TypeVar("_O", bound=object)
@@ -281,11 +280,13 @@ class scoped_session(Generic[_S]):
Session = scoped_session(sessionmaker())
class MyClass:
query: QueryPropertyDescriptor = Session.query_property()
# after mappers are defined
result = MyClass.query.filter(MyClass.name=='foo').all()
result = MyClass.query.filter(MyClass.name == "foo").all()
Produces instances of the session's configured query class by
default. To override and use a custom implementation, provide
@@ -534,12 +535,12 @@ class scoped_session(Generic[_S]):
behalf of the :class:`_orm.scoping.scoped_session` class.
This method provides for same "reset-only" behavior that the
:meth:_orm.Session.close method has provided historically, where the
:meth:`_orm.Session.close` method has provided historically, where the
state of the :class:`_orm.Session` is reset as though the object were
brand new, and ready to be used again.
The method may then be useful for :class:`_orm.Session` objects
This method may then be useful for :class:`_orm.Session` objects
which set :paramref:`_orm.Session.close_resets_only` to ``False``,
so that "reset only" behavior is still available from this method.
so that "reset only" behavior is still available.
.. versionadded:: 2.0.22
@@ -682,8 +683,7 @@ class scoped_session(Generic[_S]):
bind_arguments: Optional[_BindArguments] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
) -> Result[_T]:
...
) -> Result[_T]: ...
@overload
def execute(
@@ -695,8 +695,7 @@ class scoped_session(Generic[_S]):
bind_arguments: Optional[_BindArguments] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
) -> CursorResult[Any]:
...
) -> CursorResult[Any]: ...
@overload
def execute(
@@ -708,8 +707,7 @@ class scoped_session(Generic[_S]):
bind_arguments: Optional[_BindArguments] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
) -> Result[Any]:
...
) -> Result[Any]: ...
def execute(
self,
@@ -734,9 +732,8 @@ class scoped_session(Generic[_S]):
E.g.::
from sqlalchemy import select
result = session.execute(
select(User).where(User.id == 5)
)
result = session.execute(select(User).where(User.id == 5))
The API contract of :meth:`_orm.Session.execute` is similar to that
of :meth:`_engine.Connection.execute`, the :term:`2.0 style` version
@@ -966,10 +963,7 @@ class scoped_session(Generic[_S]):
some_object = session.get(VersionedFoo, (5, 10))
some_object = session.get(
VersionedFoo,
{"id": 5, "version_id": 10}
)
some_object = session.get(VersionedFoo, {"id": 5, "version_id": 10})
.. versionadded:: 1.4 Added :meth:`_orm.Session.get`, which is moved
from the now legacy :meth:`_orm.Query.get` method.
@@ -1092,8 +1086,7 @@ class scoped_session(Generic[_S]):
Proxied for the :class:`_orm.Session` class on
behalf of the :class:`_orm.scoping.scoped_session` class.
Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query
selects no rows.
Raises :class:`_exc.NoResultFound` if the query selects no rows.
For a detailed documentation of the arguments see the
method :meth:`.Session.get`.
@@ -1232,7 +1225,7 @@ class scoped_session(Generic[_S]):
This method retrieves the history for each instrumented
attribute on the instance and performs a comparison of the current
value to its previously committed value, if any.
value to its previously flushed or committed value, if any.
It is in effect a more expensive and accurate
version of checking for the given instance in the
@@ -1574,14 +1567,12 @@ class scoped_session(Generic[_S]):
return self._proxied.merge(instance, load=load, options=options)
@overload
def query(self, _entity: _EntityType[_O]) -> Query[_O]:
...
def query(self, _entity: _EntityType[_O]) -> Query[_O]: ...
@overload
def query(
self, _colexpr: TypedColumnsClauseRole[_T]
) -> RowReturningQuery[Tuple[_T]]:
...
) -> RowReturningQuery[Tuple[_T]]: ...
# START OVERLOADED FUNCTIONS self.query RowReturningQuery 2-8
@@ -1591,14 +1582,12 @@ class scoped_session(Generic[_S]):
@overload
def query(
self, __ent0: _TCCA[_T0], __ent1: _TCCA[_T1]
) -> RowReturningQuery[Tuple[_T0, _T1]]:
...
) -> RowReturningQuery[Tuple[_T0, _T1]]: ...
@overload
def query(
self, __ent0: _TCCA[_T0], __ent1: _TCCA[_T1], __ent2: _TCCA[_T2]
) -> RowReturningQuery[Tuple[_T0, _T1, _T2]]:
...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2]]: ...
@overload
def query(
@@ -1607,8 +1596,7 @@ class scoped_session(Generic[_S]):
__ent1: _TCCA[_T1],
__ent2: _TCCA[_T2],
__ent3: _TCCA[_T3],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3]]:
...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3]]: ...
@overload
def query(
@@ -1618,8 +1606,7 @@ class scoped_session(Generic[_S]):
__ent2: _TCCA[_T2],
__ent3: _TCCA[_T3],
__ent4: _TCCA[_T4],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4]]:
...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4]]: ...
@overload
def query(
@@ -1630,8 +1617,7 @@ class scoped_session(Generic[_S]):
__ent3: _TCCA[_T3],
__ent4: _TCCA[_T4],
__ent5: _TCCA[_T5],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5]]:
...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5]]: ...
@overload
def query(
@@ -1643,8 +1629,7 @@ class scoped_session(Generic[_S]):
__ent4: _TCCA[_T4],
__ent5: _TCCA[_T5],
__ent6: _TCCA[_T6],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6]]:
...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6]]: ...
@overload
def query(
@@ -1657,16 +1642,14 @@ class scoped_session(Generic[_S]):
__ent5: _TCCA[_T5],
__ent6: _TCCA[_T6],
__ent7: _TCCA[_T7],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7]]:
...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7]]: ...
# END OVERLOADED FUNCTIONS self.query
@overload
def query(
self, *entities: _ColumnsClauseArgument[Any], **kwargs: Any
) -> Query[Any]:
...
) -> Query[Any]: ...
def query(
self, *entities: _ColumnsClauseArgument[Any], **kwargs: Any
@@ -1818,8 +1801,7 @@ class scoped_session(Generic[_S]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> Optional[_T]:
...
) -> Optional[_T]: ...
@overload
def scalar(
@@ -1830,8 +1812,7 @@ class scoped_session(Generic[_S]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> Any:
...
) -> Any: ...
def scalar(
self,
@@ -1873,8 +1854,7 @@ class scoped_session(Generic[_S]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> ScalarResult[_T]:
...
) -> ScalarResult[_T]: ...
@overload
def scalars(
@@ -1885,8 +1865,7 @@ class scoped_session(Generic[_S]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> ScalarResult[Any]:
...
) -> ScalarResult[Any]: ...
def scalars(
self,