mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-07-29 03:06:43 +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`:
|
||||
|
||||
Reference in New Issue
Block a user