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 @@
# util/_collections.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
@@ -9,7 +9,6 @@
"""Collection classes and helpers."""
from __future__ import annotations
import collections.abc as collections_abc
import operator
import threading
import types
@@ -17,6 +16,7 @@ import typing
from typing import Any
from typing import Callable
from typing import cast
from typing import Container
from typing import Dict
from typing import FrozenSet
from typing import Generic
@@ -36,6 +36,7 @@ from typing import ValuesView
import weakref
from ._has_cy import HAS_CYEXTENSION
from .typing import is_non_string_iterable
from .typing import Literal
from .typing import Protocol
@@ -79,8 +80,8 @@ def merge_lists_w_ordering(a: List[Any], b: List[Any]) -> List[Any]:
Example::
>>> a = ['__tablename__', 'id', 'x', 'created_at']
>>> b = ['id', 'name', 'data', 'y', 'created_at']
>>> a = ["__tablename__", "id", "x", "created_at"]
>>> b = ["id", "name", "data", "y", "created_at"]
>>> merge_lists_w_ordering(a, b)
['__tablename__', 'id', 'name', 'data', 'y', 'x', 'created_at']
@@ -227,12 +228,10 @@ class Properties(Generic[_T]):
self._data.update(value)
@overload
def get(self, key: str) -> Optional[_T]:
...
def get(self, key: str) -> Optional[_T]: ...
@overload
def get(self, key: str, default: Union[_DT, _T]) -> Union[_DT, _T]:
...
def get(self, key: str, default: Union[_DT, _T]) -> Union[_DT, _T]: ...
def get(
self, key: str, default: Optional[Union[_DT, _T]] = None
@@ -419,9 +418,7 @@ def coerce_generator_arg(arg: Any) -> List[Any]:
def to_list(x: Any, default: Optional[List[Any]] = None) -> List[Any]:
if x is None:
return default # type: ignore
if not isinstance(x, collections_abc.Iterable) or isinstance(
x, (str, bytes)
):
if not is_non_string_iterable(x):
return [x]
elif isinstance(x, list):
return x
@@ -429,15 +426,14 @@ def to_list(x: Any, default: Optional[List[Any]] = None) -> List[Any]:
return list(x)
def has_intersection(set_, iterable):
def has_intersection(set_: Container[Any], iterable: Iterable[Any]) -> bool:
r"""return True if any items of set\_ are present in iterable.
Goes through special effort to ensure __hash__ is not called
on items in iterable that don't support it.
"""
# TODO: optimize, write in C, etc.
return bool(set_.intersection([i for i in iterable if i.__hash__]))
return any(i in set_ for i in iterable if i.__hash__)
def to_set(x):
@@ -458,7 +454,9 @@ def to_column_set(x: Any) -> Set[Any]:
return x
def update_copy(d, _new=None, **kw):
def update_copy(
d: Dict[Any, Any], _new: Optional[Dict[Any, Any]] = None, **kw: Any
) -> Dict[Any, Any]:
"""Copy the given dict and update with the given values."""
d = d.copy()
@@ -522,12 +520,10 @@ class LRUCache(typing.MutableMapping[_KT, _VT]):
return self._counter
@overload
def get(self, key: _KT) -> Optional[_VT]:
...
def get(self, key: _KT) -> Optional[_VT]: ...
@overload
def get(self, key: _KT, default: Union[_VT, _T]) -> Union[_VT, _T]:
...
def get(self, key: _KT, default: Union[_VT, _T]) -> Union[_VT, _T]: ...
def get(
self, key: _KT, default: Optional[Union[_VT, _T]] = None
@@ -589,13 +585,11 @@ class LRUCache(typing.MutableMapping[_KT, _VT]):
class _CreateFuncType(Protocol[_T_co]):
def __call__(self) -> _T_co:
...
def __call__(self) -> _T_co: ...
class _ScopeFuncType(Protocol):
def __call__(self) -> Any:
...
def __call__(self) -> Any: ...
class ScopedRegistry(Generic[_T]):