Always alias collections.abc.Set (#6712)

This commit is contained in:
Alex Waygood
2021-12-27 16:09:47 +00:00
committed by GitHub
parent 51a2cd1289
commit 975b3e901b
5 changed files with 14 additions and 10 deletions

View File

@@ -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

View File

@@ -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: ...

View File

@@ -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

View File

@@ -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]]: ...

View File

@@ -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":