diff --git a/stdlib/concurrent/futures/thread.pyi b/stdlib/concurrent/futures/thread.pyi index 5ad5b65d3..b3f7ac82c 100644 --- a/stdlib/concurrent/futures/thread.pyi +++ b/stdlib/concurrent/futures/thread.pyi @@ -1,6 +1,6 @@ import queue import sys -from collections.abc import Iterable, Mapping, Set # equivalent to typing.AbstractSet, not builtins.set +from collections.abc import Iterable, Mapping, Set as AbstractSet from threading import Lock, Semaphore, Thread from typing import Any, Callable, Generic, Tuple, TypeVar from weakref import ref @@ -46,7 +46,7 @@ if sys.version_info >= (3, 7): class ThreadPoolExecutor(Executor): _max_workers: int _idle_semaphore: Semaphore - _threads: Set[Thread] + _threads: AbstractSet[Thread] _broken: bool _shutdown: bool _shutdown_lock: Lock diff --git a/stdlib/unittest/case.pyi b/stdlib/unittest/case.pyi index 602a5020b..370e35868 100644 --- a/stdlib/unittest/case.pyi +++ b/stdlib/unittest/case.pyi @@ -3,7 +3,7 @@ import logging import sys import unittest.result from _typeshed import Self -from collections.abc import Set # equivalent to typing.AbstractSet, not builtins.set +from collections.abc import Set as AbstractSet from contextlib import AbstractContextManager from types import TracebackType from typing import ( @@ -201,7 +201,7 @@ class TestCase: ) -> None: ... def assertListEqual(self, list1: list[Any], list2: list[Any], msg: Any = ...) -> None: ... def assertTupleEqual(self, tuple1: Tuple[Any, ...], tuple2: Tuple[Any, ...], msg: Any = ...) -> None: ... - def assertSetEqual(self, set1: Set[object], set2: Set[object], msg: Any = ...) -> None: ... + def assertSetEqual(self, set1: AbstractSet[object], set2: AbstractSet[object], msg: Any = ...) -> None: ... def assertDictEqual(self, d1: Mapping[Any, object], d2: Mapping[Any, object], msg: Any = ...) -> None: ... def fail(self, msg: Any = ...) -> NoReturn: ... def countTestCases(self) -> int: ... diff --git a/stubs/Pygments/pygments/style.pyi b/stubs/Pygments/pygments/style.pyi index f6e0072ee..97ff2ff86 100644 --- a/stubs/Pygments/pygments/style.pyi +++ b/stubs/Pygments/pygments/style.pyi @@ -1,9 +1,9 @@ -from collections.abc import Iterator, Mapping, Set +from collections.abc import Iterator, Mapping, Set as AbstractSet from typing_extensions import TypedDict from pygments.token import _TokenType -ansicolors: Set[str] # not intended to be mutable (== typing.AbstractSet, not builtins.set) +ansicolors: AbstractSet[str] # not intended to be mutable class _StyleDict(TypedDict): color: str | None diff --git a/stubs/dateparser/dateparser/search/__init__.pyi b/stubs/dateparser/dateparser/search/__init__.pyi index e14bcc05f..2fbbdcbb0 100644 --- a/stubs/dateparser/dateparser/search/__init__.pyi +++ b/stubs/dateparser/dateparser/search/__init__.pyi @@ -1,5 +1,5 @@ import sys -from collections.abc import Mapping, Set +from collections.abc import Mapping, Set as AbstractSet from datetime import datetime from typing import Any, Tuple, overload @@ -11,14 +11,14 @@ else: @overload def search_dates( text: str, - languages: list[str] | Tuple[str, ...] | Set[str] | None, + languages: list[str] | Tuple[str, ...] | AbstractSet[str] | None, settings: Mapping[Any, Any] | None, add_detected_language: Literal[True], ) -> list[tuple[str, datetime, str]]: ... @overload def search_dates( text: str, - languages: list[str] | Tuple[str, ...] | Set[str] | None = ..., + languages: list[str] | Tuple[str, ...] | AbstractSet[str] | None = ..., settings: Mapping[Any, Any] | None = ..., add_detected_language: Literal[False] = ..., ) -> list[tuple[str, datetime]]: ... diff --git a/tests/check_new_syntax.py b/tests/check_new_syntax.py index 906160fe7..6c1358068 100755 --- a/tests/check_new_syntax.py +++ b/tests/check_new_syntax.py @@ -99,7 +99,11 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]: def visit_ImportFrom(self, node: ast.ImportFrom) -> None: if node.module == "collections.abc": imported_classes = node.names - if any(cls.name == "Set" for cls in imported_classes): + if any(cls.name == "Set" and cls.asname != "AbstractSet" for cls in imported_classes): + errors.append( + f"{path}:{node.lineno}: " + f"Use `from collections.abc import Set as AbstractSet` to avoid confusion with `builtins.set`" + ) self.set_from_collections_abc = True elif node.module == "typing_extensions":