mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-23 12:21:27 +08:00
Use TypeAlias where possible for type aliases (#7630)
This commit is contained in:
@@ -3,11 +3,12 @@
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import Any, Protocol
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
DBAPITypeCode = Any | None
|
||||
DBAPITypeCode: TypeAlias = Any | None
|
||||
# Strictly speaking, this should be a Sequence, but the type system does
|
||||
# not support fixed-length sequences.
|
||||
DBAPIColumnDescription = tuple[str, DBAPITypeCode, int | None, int | None, int | None, int | None, bool | None]
|
||||
DBAPIColumnDescription: TypeAlias = tuple[str, DBAPITypeCode, int | None, int | None, int | None, int | None, bool | None]
|
||||
|
||||
class DBAPIConnection(Protocol):
|
||||
def close(self) -> object: ...
|
||||
|
||||
@@ -3,6 +3,7 @@ from abc import abstractmethod
|
||||
from collections.abc import Mapping
|
||||
from types import TracebackType
|
||||
from typing import Any, Callable, TypeVar, overload
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
from ..dbapi import DBAPIConnection
|
||||
from ..log import Identified, _EchoFlag, echo_property
|
||||
@@ -19,7 +20,7 @@ from .util import TransactionalContext
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
_Executable = ClauseElement | FunctionElement | DDLElement | DefaultGenerator | Compiled
|
||||
_Executable: TypeAlias = ClauseElement | FunctionElement | DDLElement | DefaultGenerator | Compiled
|
||||
|
||||
class Connection(Connectable):
|
||||
engine: Engine
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from _typeshed import Self, SupportsItems
|
||||
from collections.abc import Iterable, Mapping, Sequence
|
||||
from typing import Any, NamedTuple
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
from ..util import immutabledict
|
||||
from .interfaces import Dialect
|
||||
@@ -15,7 +16,7 @@ class _URLTuple(NamedTuple):
|
||||
database: str | None
|
||||
query: immutabledict[str, str | tuple[str, ...]]
|
||||
|
||||
_Query = Mapping[str, str | Sequence[str]] | Sequence[tuple[str, str | Sequence[str]]]
|
||||
_Query: TypeAlias = Mapping[str, str | Sequence[str]] | Sequence[tuple[str, str | Sequence[str]]]
|
||||
|
||||
class URL(_URLTuple):
|
||||
@classmethod
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from _typeshed import Self
|
||||
from logging import Logger
|
||||
from typing import Any, TypeVar, overload
|
||||
from typing_extensions import Literal
|
||||
from typing_extensions import Literal, TypeAlias
|
||||
|
||||
_ClsT = TypeVar("_ClsT", bound=type)
|
||||
_EchoFlag = bool | Literal["debug"] | None
|
||||
_EchoFlag: TypeAlias = bool | Literal["debug"] | None
|
||||
|
||||
rootlogger: Any
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from collections.abc import Callable
|
||||
from typing import Any, ClassVar, TypeVar, overload
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
from ..engine.interfaces import Connectable
|
||||
from ..sql.schema import MetaData
|
||||
@@ -21,7 +22,7 @@ class _DeclarativeBase(Any): # super classes are dynamic
|
||||
__class_getitem__: ClassVar[Any]
|
||||
|
||||
# Meta class (or function) that creates a _DeclarativeBase class.
|
||||
_DeclarativeBaseMeta = Callable[[str, tuple[type[Any], ...], dict[str, Any]], _DeclT]
|
||||
_DeclarativeBaseMeta: TypeAlias = Callable[[str, tuple[type[Any], ...], dict[str, Any]], _DeclT]
|
||||
|
||||
def has_inherited_table(cls: type[Any]) -> bool: ...
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import sys
|
||||
from _typeshed import Self, SupportsKeysAndGetItem
|
||||
from collections.abc import Callable, Iterable, Iterator, Mapping
|
||||
from typing import Any, Generic, NoReturn, TypeVar, overload
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
from ..cimmutabledict import immutabledict as immutabledict
|
||||
from ..sql.elements import ColumnElement
|
||||
@@ -178,7 +179,7 @@ class WeakPopulateDict(dict[Any, Any]):
|
||||
|
||||
column_set = set
|
||||
column_dict = dict
|
||||
ordered_column_set = OrderedSet[ColumnElement[Any]]
|
||||
ordered_column_set: TypeAlias = OrderedSet[ColumnElement[Any]]
|
||||
|
||||
def unique_list(seq: Iterable[_T], hashfunc: Callable[[_T], Any] | None = ...) -> list[_T]: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user