mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-06 21:43:59 +08:00
Import names from typing directly rather than importing module (#13761)
This commit is contained in:
@@ -2,18 +2,18 @@ from __future__ import annotations
|
||||
|
||||
import mmap
|
||||
import re
|
||||
import typing as t
|
||||
from typing import AnyStr, Match, Optional
|
||||
from typing_extensions import assert_type
|
||||
|
||||
|
||||
def check_search(str_pat: re.Pattern[str], bytes_pat: re.Pattern[bytes]) -> None:
|
||||
assert_type(str_pat.search("x"), t.Optional[t.Match[str]])
|
||||
assert_type(bytes_pat.search(b"x"), t.Optional[t.Match[bytes]])
|
||||
assert_type(bytes_pat.search(bytearray(b"x")), t.Optional[t.Match[bytes]])
|
||||
assert_type(bytes_pat.search(mmap.mmap(0, 10)), t.Optional[t.Match[bytes]])
|
||||
assert_type(str_pat.search("x"), Optional[Match[str]])
|
||||
assert_type(bytes_pat.search(b"x"), Optional[Match[bytes]])
|
||||
assert_type(bytes_pat.search(bytearray(b"x")), Optional[Match[bytes]])
|
||||
assert_type(bytes_pat.search(mmap.mmap(0, 10)), Optional[Match[bytes]])
|
||||
|
||||
|
||||
def check_search_with_AnyStr(pattern: re.Pattern[t.AnyStr], string: t.AnyStr) -> re.Match[t.AnyStr]:
|
||||
def check_search_with_AnyStr(pattern: re.Pattern[AnyStr], string: AnyStr) -> re.Match[AnyStr]:
|
||||
"""See issue #9591"""
|
||||
match = pattern.search(string)
|
||||
if match is None:
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import typing as t
|
||||
from typing import Any, KeysView, TypeVar
|
||||
|
||||
KT = t.TypeVar("KT")
|
||||
KT = TypeVar("KT")
|
||||
|
||||
|
||||
class MyKeysView(t.KeysView[KT]):
|
||||
class MyKeysView(KeysView[KT]):
|
||||
pass
|
||||
|
||||
|
||||
d: dict[t.Any, t.Any] = {}
|
||||
d: dict[Any, Any] = {}
|
||||
dict_keys = type(d.keys())
|
||||
|
||||
# This should not cause an error like `Member "register" is unknown`:
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
# See the README.md file in this directory for more information.
|
||||
|
||||
import sys
|
||||
import typing_extensions
|
||||
from collections.abc import Awaitable, Callable, Iterable, Sequence, Set as AbstractSet, Sized
|
||||
from dataclasses import Field
|
||||
from os import PathLike
|
||||
@@ -23,7 +22,7 @@ from typing import (
|
||||
final,
|
||||
overload,
|
||||
)
|
||||
from typing_extensions import Buffer, LiteralString, TypeAlias
|
||||
from typing_extensions import Buffer, LiteralString, Self as _Self, TypeAlias
|
||||
|
||||
_KT = TypeVar("_KT")
|
||||
_KT_co = TypeVar("_KT_co", covariant=True)
|
||||
@@ -329,9 +328,9 @@ class structseq(Generic[_T_co]):
|
||||
# The second parameter will accept a dict of any kind without raising an exception,
|
||||
# but only has any meaning if you supply it a dict where the keys are strings.
|
||||
# https://github.com/python/typeshed/pull/6560#discussion_r767149830
|
||||
def __new__(cls, sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> typing_extensions.Self: ...
|
||||
def __new__(cls, sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> _Self: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
def __replace__(self, **kwargs: Any) -> typing_extensions.Self: ...
|
||||
def __replace__(self, **kwargs: Any) -> _Self: ...
|
||||
|
||||
# Superset of typing.AnyStr that also includes LiteralString
|
||||
AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa: Y001
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import abc
|
||||
import enum
|
||||
import sys
|
||||
import typing
|
||||
from _collections_abc import dict_items, dict_keys, dict_values
|
||||
from _typeshed import IdentityFunction, Incomplete, Unused
|
||||
from collections.abc import (
|
||||
@@ -57,6 +56,7 @@ from typing import ( # noqa: Y022,Y037,Y038,Y039,UP035
|
||||
Tuple as Tuple,
|
||||
Type as Type,
|
||||
TypedDict as TypedDict,
|
||||
TypeVar as _TypeVar,
|
||||
Union as Union,
|
||||
_Alias,
|
||||
cast as cast,
|
||||
@@ -195,10 +195,10 @@ __all__ = [
|
||||
"CapsuleType",
|
||||
]
|
||||
|
||||
_T = typing.TypeVar("_T")
|
||||
_F = typing.TypeVar("_F", bound=Callable[..., Any])
|
||||
_TC = typing.TypeVar("_TC", bound=type[object])
|
||||
_T_co = typing.TypeVar("_T_co", covariant=True) # Any type covariant containers.
|
||||
_T = _TypeVar("_T")
|
||||
_F = _TypeVar("_F", bound=Callable[..., Any])
|
||||
_TC = _TypeVar("_TC", bound=type[object])
|
||||
_T_co = _TypeVar("_T_co", covariant=True) # Any type covariant containers.
|
||||
|
||||
class _Final: ... # This should be imported from typing but that breaks pytype
|
||||
|
||||
|
||||
Reference in New Issue
Block a user