From 72e6fc997a4e0fbd4b77b2fe1d05d2dba7892912 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Mon, 13 Dec 2021 12:19:41 +0000 Subject: [PATCH 1/2] Update AbstractSet instead of set in random and inspect `collections.abc.Set` was accidentally replaced with `set` in #6346. The prior is an alias to `typing.AbstractSet`, instead of `builtins.set`. Since `collections.abc.Set` is easily confused with `typing.Set`, it seems clearer to use `typing.AbstractSet` here. --- stdlib/inspect.pyi | 4 ++-- stdlib/random.pyi | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index 82a59d6136ab..39a040568ab9 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -23,7 +23,7 @@ from types import ( if sys.version_info >= (3, 7): from types import ClassMethodDescriptorType, WrapperDescriptorType, MemberDescriptorType, MethodDescriptorType -from typing import Any, ClassVar, NamedTuple, Protocol, Tuple, Type, TypeVar, Union +from typing import AbstractSet, Any, ClassVar, NamedTuple, Protocol, Tuple, Type, TypeVar, Union from typing_extensions import Literal, TypeGuard # @@ -317,7 +317,7 @@ class ClosureVars(NamedTuple): nonlocals: Mapping[str, Any] globals: Mapping[str, Any] builtins: Mapping[str, Any] - unbound: set[str] + unbound: AbstractSet[str] def getclosurevars(func: Callable[..., Any]) -> ClosureVars: ... def unwrap(func: Callable[..., Any], *, stop: Callable[[Any], Any] | None = ...) -> Any: ... diff --git a/stdlib/random.pyi b/stdlib/random.pyi index fd449ee1b1ae..6c2f69f2e9d8 100644 --- a/stdlib/random.pyi +++ b/stdlib/random.pyi @@ -3,7 +3,7 @@ import sys from _typeshed import SupportsLenAndGetItem from collections.abc import Callable, Iterable, MutableSequence, Sequence from fractions import Fraction -from typing import Any, ClassVar, NoReturn, Tuple, TypeVar +from typing import AbstractSet, Any, ClassVar, NoReturn, Tuple, TypeVar _T = TypeVar("_T") @@ -29,9 +29,11 @@ class Random(_random.Random): ) -> list[_T]: ... def shuffle(self, x: MutableSequence[Any], random: Callable[[], float] | None = ...) -> None: ... if sys.version_info >= (3, 9): - def sample(self, population: Sequence[_T] | set[_T], k: int, *, counts: Iterable[_T] | None = ...) -> list[_T]: ... + def sample( + self, population: Sequence[_T] | AbstractSet[_T], k: int, *, counts: Iterable[_T] | None = ... + ) -> list[_T]: ... else: - def sample(self, population: Sequence[_T] | set[_T], k: int) -> list[_T]: ... + def sample(self, population: Sequence[_T] | AbstractSet[_T], k: int) -> list[_T]: ... def random(self) -> float: ... def uniform(self, a: float, b: float) -> float: ... def triangular(self, low: float = ..., high: float = ..., mode: float | None = ...) -> float: ... @@ -73,10 +75,10 @@ def choices( def shuffle(x: MutableSequence[Any], random: Callable[[], float] | None = ...) -> None: ... if sys.version_info >= (3, 9): - def sample(population: Sequence[_T] | set[_T], k: int, *, counts: Iterable[_T] | None = ...) -> list[_T]: ... + def sample(population: Sequence[_T] | AbstractSet[_T], k: int, *, counts: Iterable[_T] | None = ...) -> list[_T]: ... else: - def sample(population: Sequence[_T] | set[_T], k: int) -> list[_T]: ... + def sample(population: Sequence[_T] | AbstractSet[_T], k: int) -> list[_T]: ... def random() -> float: ... def uniform(a: float, b: float) -> float: ... From 6ca67a0a3c37a61c707525155f60270933e874c6 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Mon, 13 Dec 2021 15:58:04 +0000 Subject: [PATCH 2/2] Import from collections.abc instead --- stdlib/inspect.pyi | 4 ++-- stdlib/random.pyi | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index 39a040568ab9..639617239459 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -3,7 +3,7 @@ import sys import types from _typeshed import Self from collections import OrderedDict -from collections.abc import Awaitable, Callable, Generator, Mapping, Sequence +from collections.abc import Awaitable, Callable, Generator, Mapping, Sequence, Set as AbstractSet from types import ( AsyncGeneratorType, BuiltinFunctionType, @@ -23,7 +23,7 @@ from types import ( if sys.version_info >= (3, 7): from types import ClassMethodDescriptorType, WrapperDescriptorType, MemberDescriptorType, MethodDescriptorType -from typing import AbstractSet, Any, ClassVar, NamedTuple, Protocol, Tuple, Type, TypeVar, Union +from typing import Any, ClassVar, NamedTuple, Protocol, Tuple, Type, TypeVar, Union from typing_extensions import Literal, TypeGuard # diff --git a/stdlib/random.pyi b/stdlib/random.pyi index 6c2f69f2e9d8..4834dab6552e 100644 --- a/stdlib/random.pyi +++ b/stdlib/random.pyi @@ -1,9 +1,9 @@ import _random import sys from _typeshed import SupportsLenAndGetItem -from collections.abc import Callable, Iterable, MutableSequence, Sequence +from collections.abc import Callable, Iterable, MutableSequence, Sequence, Set as AbstractSet from fractions import Fraction -from typing import AbstractSet, Any, ClassVar, NoReturn, Tuple, TypeVar +from typing import Any, ClassVar, NoReturn, Tuple, TypeVar _T = TypeVar("_T")