Use TypeAlias for type aliases where possible, part II (#7667)

This commit is contained in:
Alex Waygood
2022-04-20 20:02:47 +01:00
committed by GitHub
parent c653be73b8
commit b093c90a94
41 changed files with 91 additions and 90 deletions

View File

@@ -2,8 +2,9 @@ from collections.abc import Callable, Iterable
from datetime import timedelta
from logging import Logger
from typing import Any
from typing_extensions import TypeAlias
_App = Any # flask is not part of typeshed
_App: TypeAlias = Any # flask is not part of typeshed
LOG: Logger

View File

@@ -1,8 +1,9 @@
from _typeshed import Self
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
from typing import Any, overload
from typing_extensions import TypeAlias
_NDArray = Any # FIXME: no typings for numpy arrays
_NDArray: TypeAlias = Any # FIXME: no typings for numpy arrays
class _JackPositionT: ...

View File

@@ -1,5 +1,6 @@
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from typing import Any, Pattern, TypeVar, overload
from typing_extensions import TypeAlias
from . import resolver as resolver # Help mypy a bit; this is implied by loader and dumper
from .constructor import BaseConstructor
@@ -16,7 +17,7 @@ from .resolver import BaseResolver
from .tokens import *
# FIXME: the functions really return str if encoding is None, otherwise bytes. Waiting for python/mypy#5621
_Yaml = Any
_Yaml: TypeAlias = Any
__with_libyaml__: Any
__version__: str

View File

@@ -14,7 +14,7 @@ INVISIBLE_CHARACTERS_RE: Pattern[str]
INVISIBLE_REPLACEMENT_CHAR: str
# A html5lib Filter class
_Filter = Any
_Filter: TypeAlias = Any
class Cleaner:
tags: Container[str]

View File

@@ -118,7 +118,7 @@ class LRUCache(dict[_KT, _VT]):
def __init__(self, capacity: int) -> None: ...
# This exists to work around Password.str's name shadowing the str type
_str = str
_str: TypeAlias = str
class Password:
hashfunc: Callable[[bytes], _HashType]

View File

@@ -1,5 +1,6 @@
from collections.abc import Iterable, Mapping
from typing import Any
from typing_extensions import TypeAlias
from urllib.parse import ParseResult, SplitResult
from requests.auth import AuthBase
@@ -9,7 +10,7 @@ from requests.structures import CaseInsensitiveDict
from .lib.url import URL
from .objects import Calendar, DAVObject, Principal
_Element = Any # actually lxml.etree._Element
_Element: TypeAlias = Any # actually lxml.etree._Element
class DAVResponse:
reason: str

View File

@@ -1,8 +1,9 @@
from _typeshed import Self
from collections.abc import Iterable
from typing import Any, ClassVar
from typing_extensions import TypeAlias
_Element = Any # actually lxml.etree._Element
_Element: TypeAlias = Any # actually lxml.etree._Element
class BaseElement:
tag: ClassVar[str | None]

View File

@@ -2,7 +2,7 @@ import datetime
from _typeshed import Self
from collections.abc import Iterable, Iterator, Mapping
from typing import Any, TypeVar, overload
from typing_extensions import Literal
from typing_extensions import Literal, TypeAlias
from urllib.parse import ParseResult, SplitResult
from vobject.base import VBase
@@ -13,7 +13,7 @@ from .lib.url import URL
_CC = TypeVar("_CC", bound=CalendarObjectResource)
_vCalAddress = Any # actually icalendar.vCalAddress
_vCalAddress: TypeAlias = Any # actually icalendar.vCalAddress
class DAVObject:
id: str | None

View File

@@ -1,4 +1,5 @@
import sys
from builtins import dict as _dict # alias to avoid conflicts with attribute name
from collections.abc import Callable, Iterator
from typing import Any, NamedTuple, Pattern, TypeVar
from typing_extensions import ParamSpec
@@ -31,8 +32,6 @@ else:
DEF: Pattern[str]
_dict = dict # conflicts with attribute name
class FunctionMaker:
args: list[str]
varargs: str | None

View File

@@ -1,4 +1,5 @@
import optparse
from builtins import list as _list # alias to avoid name clashes with fields named list
from collections.abc import Iterable
from typing import Any
from typing_extensions import Literal, TypeAlias
@@ -7,8 +8,6 @@ from docutils import ApplicationError
from docutils.io import FileOutput
from docutils.nodes import document
_list = list
class DependencyList:
list: _list[str]
file: FileOutput | None

View File

@@ -182,7 +182,7 @@ class _Parser:
def ParseLines(self, lines: Iterable[Text | bytes], message: _M) -> _M: ...
def MergeLines(self, lines: Iterable[Text | bytes], message: _M) -> _M: ...
_ParseError = ParseError
_ParseError: TypeAlias = ParseError
class Tokenizer:
token: str = ...

View File

@@ -275,7 +275,7 @@ class Xid:
def __getitem__(self, __index): ...
def __len__(self): ...
_cursor = cursor
_cursor: TypeAlias = cursor
_T_cur = TypeVar("_T_cur", bound=_cursor)
class connection:

View File

@@ -159,32 +159,32 @@ def in_string_annotation(func: _F) -> _F: ...
def make_tokens(code: str | bytes) -> tuple[TokenInfo, ...]: ...
if sys.version_info >= (3, 8):
_NamedExpr = ast.NamedExpr
_NamedExpr: TypeAlias = ast.NamedExpr
else:
_NamedExpr = Any
_NamedExpr: TypeAlias = Any
if sys.version_info >= (3, 10):
_Match = ast.Match
_MatchCase = ast.match_case
_MatchValue = ast.MatchValue
_MatchSingleton = ast.MatchSingleton
_MatchSequence = ast.MatchSequence
_MatchStar = ast.MatchStar
_MatchMapping = ast.MatchMapping
_MatchClass = ast.MatchClass
_MatchAs = ast.MatchAs
_MatchOr = ast.MatchOr
_Match: TypeAlias = ast.Match
_MatchCase: TypeAlias = ast.match_case
_MatchValue: TypeAlias = ast.MatchValue
_MatchSingleton: TypeAlias = ast.MatchSingleton
_MatchSequence: TypeAlias = ast.MatchSequence
_MatchStar: TypeAlias = ast.MatchStar
_MatchMapping: TypeAlias = ast.MatchMapping
_MatchClass: TypeAlias = ast.MatchClass
_MatchAs: TypeAlias = ast.MatchAs
_MatchOr: TypeAlias = ast.MatchOr
else:
_Match = Any
_MatchCase = Any
_MatchValue = Any
_MatchSingleton = Any
_MatchSequence = Any
_MatchStar = Any
_MatchMapping = Any
_MatchClass = Any
_MatchAs = Any
_MatchOr = Any
_Match: TypeAlias = Any
_MatchCase: TypeAlias = Any
_MatchValue: TypeAlias = Any
_MatchSingleton: TypeAlias = Any
_MatchSequence: TypeAlias = Any
_MatchStar: TypeAlias = Any
_MatchMapping: TypeAlias = Any
_MatchClass: TypeAlias = Any
_MatchAs: TypeAlias = Any
_MatchOr: TypeAlias = Any
class Checker:
nodeDepth: int

View File

@@ -1,6 +1,7 @@
from _typeshed import Self
from datetime import date, datetime, timedelta
from typing import SupportsFloat, TypeVar, overload
from typing_extensions import TypeAlias
from ._common import weekday
@@ -8,7 +9,7 @@ from ._common import weekday
_SelfT = TypeVar("_SelfT", bound=relativedelta)
_DateT = TypeVar("_DateT", date, datetime)
# Work around attribute and type having the same name.
_weekday = weekday
_weekday: TypeAlias = weekday
MO: weekday
TU: weekday

View File

@@ -1,5 +1,6 @@
import datetime
from typing import Any, Iterable
from typing_extensions import TypeAlias
from ._common import weekday as weekdaybase
@@ -81,7 +82,7 @@ class _iterinfo:
def mtimeset(self, hour, minute, second): ...
def stimeset(self, hour, minute, second): ...
_rrule = rrule
_rrule: TypeAlias = rrule
class rruleset(rrulebase):
class _genitem:

View File

@@ -1,6 +1,7 @@
from _typeshed import Self
from collections.abc import Mapping
from typing import Any
from typing_extensions import TypeAlias
from .retry import Retry
@@ -12,7 +13,7 @@ SYM_EMPTY: Any
SERVER_CLOSED_CONNECTION_ERROR: Any
# Options as passed to Pool.get_connection().
_ConnectionPoolOptions = Any
_ConnectionPoolOptions: TypeAlias = Any
class BaseParser:
EXCEPTION_CLASSES: Any

View File

@@ -9,7 +9,7 @@ from . import adapters, auth as _auth, compat, cookies, exceptions, hooks, model
from .models import Response
from .structures import CaseInsensitiveDict as CaseInsensitiveDict
_BaseAdapter = adapters.BaseAdapter
_BaseAdapter: TypeAlias = adapters.BaseAdapter
OrderedDict = compat.OrderedDict
cookiejar_from_dict = cookies.cookiejar_from_dict
extract_cookies_to_jar = cookies.extract_cookies_to_jar

View File

@@ -1,5 +1,6 @@
from collections.abc import Iterator
from typing import Any
from typing_extensions import TypeAlias
class NodeVisitor:
def visit(self, node: AST) -> Any: ...
@@ -152,7 +153,7 @@ class Break(stmt): ...
class Continue(stmt): ...
class slice(AST): ...
_slice = slice # this lets us type the variable named 'slice' below
_slice: TypeAlias = slice # this lets us type the variable named 'slice' below
class Slice(slice):
lower: expr | None

View File

@@ -1,5 +1,6 @@
from collections.abc import Iterator
from typing import Any
from typing_extensions import TypeAlias
class NodeVisitor:
def visit(self, node: AST) -> Any: ...
@@ -168,7 +169,7 @@ class Break(stmt): ...
class Continue(stmt): ...
class slice(AST): ...
_slice = slice # this lets us type the variable named 'slice' below
_slice: TypeAlias = slice # this lets us type the variable named 'slice' below
class Slice(slice):
lower: expr | None

View File

@@ -3,10 +3,11 @@ from io import BytesIO
from logging import Logger
from socket import socket
from typing import Any
from typing_extensions import TypeAlias
from . import compat as compat, utilities as utilities
_socket = socket
_socket: TypeAlias = socket
socket_map: Mapping[int, socket]
map: Mapping[int, socket]