mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-08-01 05:30:23 +08:00
Drop Python 3.8 branches (#13776)
This commit is contained in:
@@ -10,14 +10,14 @@ from importlib.machinery import ModuleSpec
|
||||
from types import ModuleType
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
# Assert that some Path classes are Traversable.
|
||||
if sys.version_info >= (3, 9):
|
||||
def traverse(t: importlib.abc.Traversable) -> None:
|
||||
pass
|
||||
|
||||
def traverse(t: importlib.abc.Traversable) -> None:
|
||||
pass
|
||||
|
||||
traverse(pathlib.Path())
|
||||
traverse(zipfile.Path(""))
|
||||
traverse(pathlib.Path())
|
||||
traverse(zipfile.Path(""))
|
||||
|
||||
|
||||
class MetaFinder:
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import platform
|
||||
import sys
|
||||
from typing_extensions import assert_type
|
||||
|
||||
# platform.uname_result emulates a 6 field named tuple, but on 3.9+ the processor
|
||||
# field is lazily evaluated, which results in it being a little funky.
|
||||
uname = platform.uname()
|
||||
if sys.version_info >= (3, 9):
|
||||
myuname = platform.uname_result("Darwin", "local", "22.5.0", "Darwin Kernel Version 22.5.0", "arm64")
|
||||
else:
|
||||
myuname = platform.uname_result("Darwin", "local", "22.5.0", "Darwin Kernel Version 22.5.0", "arm64", "arm")
|
||||
myuname = platform.uname_result("Darwin", "local", "22.5.0", "Darwin Kernel Version 22.5.0", "arm64")
|
||||
|
||||
assert_type(uname, platform.uname_result)
|
||||
assert_type(myuname, platform.uname_result)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from typing_extensions import assert_type
|
||||
from xml.dom.minidom import Document
|
||||
|
||||
@@ -10,10 +9,9 @@ assert_type(document.toxml(), str)
|
||||
assert_type(document.toxml(encoding=None), str)
|
||||
assert_type(document.toxml(encoding="UTF8"), bytes)
|
||||
assert_type(document.toxml("UTF8"), bytes)
|
||||
if sys.version_info >= (3, 9):
|
||||
assert_type(document.toxml(standalone=True), str)
|
||||
assert_type(document.toxml("UTF8", True), bytes)
|
||||
assert_type(document.toxml(encoding="UTF8", standalone=True), bytes)
|
||||
assert_type(document.toxml(standalone=True), str)
|
||||
assert_type(document.toxml("UTF8", True), bytes)
|
||||
assert_type(document.toxml(encoding="UTF8", standalone=True), bytes)
|
||||
|
||||
|
||||
# Because toprettyxml can mix positional and keyword variants of the "encoding" argument, which
|
||||
@@ -23,13 +21,11 @@ if sys.version_info >= (3, 9):
|
||||
assert_type(document.toprettyxml(), str)
|
||||
assert_type(document.toprettyxml(encoding=None), str)
|
||||
assert_type(document.toprettyxml(encoding="UTF8"), bytes)
|
||||
if sys.version_info >= (3, 9):
|
||||
assert_type(document.toprettyxml(standalone=True), str)
|
||||
assert_type(document.toprettyxml(encoding="UTF8", standalone=True), bytes)
|
||||
assert_type(document.toprettyxml(standalone=True), str)
|
||||
assert_type(document.toprettyxml(encoding="UTF8", standalone=True), bytes)
|
||||
# Test cases unique to toprettyxml
|
||||
assert_type(document.toprettyxml(" "), str)
|
||||
assert_type(document.toprettyxml(" ", "\r\n"), str)
|
||||
assert_type(document.toprettyxml(" ", "\r\n", "UTF8"), bytes)
|
||||
if sys.version_info >= (3, 9):
|
||||
assert_type(document.toprettyxml(" ", "\r\n", "UTF8", True), bytes)
|
||||
assert_type(document.toprettyxml(" ", "\r\n", standalone=True), str)
|
||||
assert_type(document.toprettyxml(" ", "\r\n", "UTF8", True), bytes)
|
||||
assert_type(document.toprettyxml(" ", "\r\n", standalone=True), str)
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
"""
|
||||
Tests for `defaultdict.__or__` and `defaultdict.__ror__`.
|
||||
These methods were only added in py39.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from typing import Mapping, TypeVar, Union
|
||||
from typing_extensions import Self, assert_type
|
||||
|
||||
_KT = TypeVar("_KT")
|
||||
_VT = TypeVar("_VT")
|
||||
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
|
||||
class CustomDefaultDictSubclass(defaultdict[_KT, _VT]):
|
||||
pass
|
||||
|
||||
class CustomMappingWithDunderOr(Mapping[_KT, _VT]):
|
||||
def __or__(self, other: Mapping[_KT, _VT]) -> dict[_KT, _VT]:
|
||||
return {}
|
||||
|
||||
def __ror__(self, other: Mapping[_KT, _VT]) -> dict[_KT, _VT]:
|
||||
return {}
|
||||
|
||||
def __ior__(self, other: Mapping[_KT, _VT]) -> Self:
|
||||
return self
|
||||
|
||||
def test_defaultdict_dot_or(
|
||||
a: defaultdict[int, int],
|
||||
b: CustomDefaultDictSubclass[int, int],
|
||||
c: defaultdict[str, str],
|
||||
d: Mapping[int, int],
|
||||
e: CustomMappingWithDunderOr[str, str],
|
||||
) -> None:
|
||||
assert_type(a | b, defaultdict[int, int])
|
||||
|
||||
# In contrast to `dict.__or__`, `defaultdict.__or__` returns `Self` if called on a subclass of `defaultdict`:
|
||||
assert_type(b | a, CustomDefaultDictSubclass[int, int])
|
||||
|
||||
assert_type(a | c, defaultdict[Union[int, str], Union[int, str]])
|
||||
|
||||
# arbitrary mappings are not accepted by `defaultdict.__or__`;
|
||||
# it has to be a subclass of `dict`
|
||||
a | d # type: ignore
|
||||
|
||||
# but Mappings such as `os._Environ` or `CustomMappingWithDunderOr`,
|
||||
# which define `__ror__` methods that accept `dict`, are fine
|
||||
# (`os._Environ.__(r)or__` always returns `dict`, even if a `defaultdict` is passed):
|
||||
assert_type(a | os.environ, dict[Union[str, int], Union[str, int]])
|
||||
assert_type(os.environ | a, dict[Union[str, int], Union[str, int]])
|
||||
|
||||
assert_type(c | os.environ, dict[str, str])
|
||||
assert_type(c | e, dict[str, str])
|
||||
|
||||
assert_type(os.environ | c, dict[str, str])
|
||||
assert_type(e | c, dict[str, str])
|
||||
|
||||
# store "untainted" `CustomMappingWithDunderOr[str, str]` to test `__ior__` against ` defaultdict[str, str]` later
|
||||
# Invalid `e |= a` causes pyright to join `Unknown` to `e`'s type
|
||||
f = e
|
||||
|
||||
e |= c
|
||||
e |= a # type: ignore
|
||||
|
||||
c |= f
|
||||
|
||||
c |= a # type: ignore
|
||||
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
Tests for `defaultdict.__or__` and `defaultdict.__ror__`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from collections import defaultdict
|
||||
from typing import Mapping, TypeVar, Union
|
||||
from typing_extensions import Self, assert_type
|
||||
|
||||
_KT = TypeVar("_KT")
|
||||
_VT = TypeVar("_VT")
|
||||
|
||||
|
||||
class CustomDefaultDictSubclass(defaultdict[_KT, _VT]):
|
||||
pass
|
||||
|
||||
|
||||
class CustomMappingWithDunderOr(Mapping[_KT, _VT]):
|
||||
def __or__(self, other: Mapping[_KT, _VT]) -> dict[_KT, _VT]:
|
||||
return {}
|
||||
|
||||
def __ror__(self, other: Mapping[_KT, _VT]) -> dict[_KT, _VT]:
|
||||
return {}
|
||||
|
||||
def __ior__(self, other: Mapping[_KT, _VT]) -> Self:
|
||||
return self
|
||||
|
||||
|
||||
def test_defaultdict_dot_or(
|
||||
a: defaultdict[int, int],
|
||||
b: CustomDefaultDictSubclass[int, int],
|
||||
c: defaultdict[str, str],
|
||||
d: Mapping[int, int],
|
||||
e: CustomMappingWithDunderOr[str, str],
|
||||
) -> None:
|
||||
assert_type(a | b, defaultdict[int, int])
|
||||
|
||||
# In contrast to `dict.__or__`, `defaultdict.__or__` returns `Self` if called on a subclass of `defaultdict`:
|
||||
assert_type(b | a, CustomDefaultDictSubclass[int, int])
|
||||
|
||||
assert_type(a | c, defaultdict[Union[int, str], Union[int, str]])
|
||||
|
||||
# arbitrary mappings are not accepted by `defaultdict.__or__`;
|
||||
# it has to be a subclass of `dict`
|
||||
a | d # type: ignore
|
||||
|
||||
# but Mappings such as `os._Environ` or `CustomMappingWithDunderOr`,
|
||||
# which define `__ror__` methods that accept `dict`, are fine
|
||||
# (`os._Environ.__(r)or__` always returns `dict`, even if a `defaultdict` is passed):
|
||||
assert_type(a | os.environ, dict[Union[str, int], Union[str, int]])
|
||||
assert_type(os.environ | a, dict[Union[str, int], Union[str, int]])
|
||||
|
||||
assert_type(c | os.environ, dict[str, str])
|
||||
assert_type(c | e, dict[str, str])
|
||||
|
||||
assert_type(os.environ | c, dict[str, str])
|
||||
assert_type(e | c, dict[str, str])
|
||||
|
||||
# store "untainted" `CustomMappingWithDunderOr[str, str]` to test `__ior__` against ` defaultdict[str, str]` later
|
||||
# Invalid `e |= a` causes pyright to join `Unknown` to `e`'s type
|
||||
f = e
|
||||
|
||||
e |= c
|
||||
e |= a # type: ignore
|
||||
|
||||
c |= f
|
||||
|
||||
c |= a # type: ignore
|
||||
Reference in New Issue
Block a user