From 9c4c192017c9d2519c438bdaaefd9236de7dcb77 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 10 Jul 2026 13:54:16 -0700 Subject: [PATCH] Avoid class-scope name collisions in stubs Class members such as list, type, cursor, Model, and datetime shadow the builtins, classes, or modules referenced by nearby annotations. ty then resolves those annotations to Unknown, which can hide invalid calls in APIs including docker, sqlite3, psycopg2, Markdown, and requests. Qualify shadowed builtins and use private aliases for colliding imports and classes. This removes 15 stdlib and 120 third-party collision diagnostics under ty 0.0.58, restores the affected public types, and fixes four existing psycopg2 type assertions. --- stdlib/_curses_panel.pyi | 8 +- stdlib/multiprocessing/managers.pyi | 5 +- stdlib/multiprocessing/pool.pyi | 4 +- stdlib/sqlite3/__init__.pyi | 31 ++-- stubs/Markdown/markdown/blockparser.pyi | 4 +- stubs/Markdown/markdown/core.pyi | 14 +- stubs/WebOb/webob/cachecontrol.pyi | 3 +- stubs/colorful/colorful/core.pyi | 2 +- stubs/docker/docker/models/configs.pyi | 4 +- stubs/docker/docker/models/containers.pyi | 149 +++++++++--------- stubs/docker/docker/models/images.pyi | 5 +- stubs/docker/docker/models/networks.pyi | 3 +- stubs/docker/docker/models/resource.pyi | 3 +- stubs/docker/docker/models/volumes.pyi | 3 +- stubs/docker/docker/types/containers.pyi | 3 +- stubs/docutils/docutils/nodes.pyi | 4 +- stubs/ephem/ephem/_libastro.pyi | 5 +- stubs/httplib2/httplib2/__init__.pyi | 3 +- stubs/peewee/peewee.pyi | 15 +- stubs/pika/pika/spec.pyi | 2 +- stubs/psycopg2/psycopg2/_psycopg.pyi | 9 +- stubs/pyluach/pyluach/dates.pyi | 3 +- stubs/pynput/pynput/keyboard/_base.pyi | 5 +- .../serial/urlhandler/protocol_loop.pyi | 4 +- stubs/python-xlib/Xlib/protocol/rq.pyi | 2 +- stubs/reportlab/reportlab/lib/utils.pyi | 12 +- .../reportlab/platypus/doctemplate.pyi | 4 +- stubs/requests/requests/sessions.pyi | 2 +- stubs/tensorflow/tensorflow/__init__.pyi | 5 +- 29 files changed, 176 insertions(+), 140 deletions(-) diff --git a/stdlib/_curses_panel.pyi b/stdlib/_curses_panel.pyi index a552a151ddf1..64205618bf41 100644 --- a/stdlib/_curses_panel.pyi +++ b/stdlib/_curses_panel.pyi @@ -1,4 +1,4 @@ -from _curses import window +from _curses import window as _window from typing import Final, final __version__: Final[str] @@ -14,14 +14,14 @@ class panel: def hidden(self) -> bool: ... def hide(self) -> None: ... def move(self, y: int, x: int, /) -> None: ... - def replace(self, win: window, /) -> None: ... + def replace(self, win: _window, /) -> None: ... def set_userptr(self, obj: object, /) -> None: ... def show(self) -> None: ... def top(self) -> None: ... def userptr(self) -> object: ... - def window(self) -> window: ... + def window(self) -> _window: ... def bottom_panel() -> panel: ... -def new_panel(win: window, /) -> panel: ... +def new_panel(win: _window, /) -> panel: ... def top_panel() -> panel: ... def update_panels() -> panel: ... diff --git a/stdlib/multiprocessing/managers.pyi b/stdlib/multiprocessing/managers.pyi index 40639e867834..0f1d4e87b0dc 100644 --- a/stdlib/multiprocessing/managers.pyi +++ b/stdlib/multiprocessing/managers.pyi @@ -1,3 +1,4 @@ +import builtins import queue import sys import threading @@ -359,9 +360,9 @@ class SyncManager(BaseManager): @overload def dict(self, iterable: Iterable[tuple[str, _VT]], /, **kwargs: _VT) -> DictProxy[str, _VT]: ... @overload - def dict(self, iterable: Iterable[list[str]], /) -> DictProxy[str, str]: ... + def dict(self, iterable: Iterable[builtins.list[str]], /) -> DictProxy[str, str]: ... @overload - def dict(self, iterable: Iterable[list[bytes]], /) -> DictProxy[bytes, bytes]: ... + def dict(self, iterable: Iterable[builtins.list[bytes]], /) -> DictProxy[bytes, bytes]: ... # Overloads are copied from builtins.list.__init__ @overload diff --git a/stdlib/multiprocessing/pool.pyi b/stdlib/multiprocessing/pool.pyi index b79f9e77359a..5642e50d0e76 100644 --- a/stdlib/multiprocessing/pool.pyi +++ b/stdlib/multiprocessing/pool.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable, Iterable, Mapping -from multiprocessing.context import DefaultContext, Process +from multiprocessing.context import DefaultContext, Process as _Process from types import GenericAlias, TracebackType from typing import Any, Final, Generic, TypeVar from typing_extensions import Self @@ -50,7 +50,7 @@ class Pool: context: Any | None = None, ) -> None: ... @staticmethod - def Process(ctx: DefaultContext, *args: Any, **kwds: Any) -> Process: ... + def Process(ctx: DefaultContext, *args: Any, **kwds: Any) -> _Process: ... def apply(self, func: Callable[..., _T], args: Iterable[Any] = (), kwds: Mapping[str, Any] = {}) -> _T: ... def apply_async( self, diff --git a/stdlib/sqlite3/__init__.pyi b/stdlib/sqlite3/__init__.pyi index 7c033bdf4325..80a02079dd05 100644 --- a/stdlib/sqlite3/__init__.pyi +++ b/stdlib/sqlite3/__init__.pyi @@ -269,28 +269,39 @@ class OperationalError(DatabaseError): ... class ProgrammingError(DatabaseError): ... class Warning(Exception): ... +_DataError: TypeAlias = DataError +_DatabaseError: TypeAlias = DatabaseError +_Error: TypeAlias = Error +_IntegrityError: TypeAlias = IntegrityError +_InterfaceError: TypeAlias = InterfaceError +_InternalError: TypeAlias = InternalError +_NotSupportedError: TypeAlias = NotSupportedError +_OperationalError: TypeAlias = OperationalError +_ProgrammingError: TypeAlias = ProgrammingError +_Warning: TypeAlias = Warning + @disjoint_base class Connection: @property - def DataError(self) -> type[DataError]: ... + def DataError(self) -> type[_DataError]: ... @property - def DatabaseError(self) -> type[DatabaseError]: ... + def DatabaseError(self) -> type[_DatabaseError]: ... @property - def Error(self) -> type[Error]: ... + def Error(self) -> type[_Error]: ... @property - def IntegrityError(self) -> type[IntegrityError]: ... + def IntegrityError(self) -> type[_IntegrityError]: ... @property - def InterfaceError(self) -> type[InterfaceError]: ... + def InterfaceError(self) -> type[_InterfaceError]: ... @property - def InternalError(self) -> type[InternalError]: ... + def InternalError(self) -> type[_InternalError]: ... @property - def NotSupportedError(self) -> type[NotSupportedError]: ... + def NotSupportedError(self) -> type[_NotSupportedError]: ... @property - def OperationalError(self) -> type[OperationalError]: ... + def OperationalError(self) -> type[_OperationalError]: ... @property - def ProgrammingError(self) -> type[ProgrammingError]: ... + def ProgrammingError(self) -> type[_ProgrammingError]: ... @property - def Warning(self) -> type[Warning]: ... + def Warning(self) -> type[_Warning]: ... @property def in_transaction(self) -> bool: ... isolation_level: _IsolationLevel diff --git a/stubs/Markdown/markdown/blockparser.pyi b/stubs/Markdown/markdown/blockparser.pyi index 9fd9f5e85609..805eb13c47c3 100644 --- a/stubs/Markdown/markdown/blockparser.pyi +++ b/stubs/Markdown/markdown/blockparser.pyi @@ -2,7 +2,7 @@ from collections.abc import Iterable from typing import Any, TypeVar from xml.etree.ElementTree import Element, ElementTree -from markdown import blockprocessors, util +from markdown import blockprocessors as _blockprocessors, util from markdown.core import Markdown _T = TypeVar("_T") @@ -13,7 +13,7 @@ class State(list[_T]): def isstate(self, state: _T) -> bool: ... class BlockParser: - blockprocessors: util.Registry[blockprocessors.BlockProcessor] + blockprocessors: util.Registry[_blockprocessors.BlockProcessor] state: State[Any] # TODO: possible to get rid of Any? md: Markdown def __init__(self, md: Markdown) -> None: ... diff --git a/stubs/Markdown/markdown/core.pyi b/stubs/Markdown/markdown/core.pyi index 80eacd4b2a49..98972399f1ea 100644 --- a/stubs/Markdown/markdown/core.pyi +++ b/stubs/Markdown/markdown/core.pyi @@ -5,7 +5,13 @@ from typing import Any, ClassVar, Literal from typing_extensions import Self from xml.etree.ElementTree import Element -from . import blockparser, inlinepatterns, postprocessors, preprocessors, treeprocessors +from . import ( + blockparser, + inlinepatterns, + postprocessors as _postprocessors, + preprocessors as _preprocessors, + treeprocessors as _treeprocessors, +) from .extensions import Extension from .util import HtmlStash, Registry @@ -14,10 +20,10 @@ __all__ = ["Markdown", "markdown", "markdownFromFile"] logger: Logger class Markdown: - preprocessors: Registry[preprocessors.Preprocessor] + preprocessors: Registry[_preprocessors.Preprocessor] inlinePatterns: Registry[inlinepatterns.Pattern] - treeprocessors: Registry[treeprocessors.Treeprocessor] - postprocessors: Registry[postprocessors.Postprocessor] + treeprocessors: Registry[_treeprocessors.Treeprocessor] + postprocessors: Registry[_postprocessors.Postprocessor] parser: blockparser.BlockParser htmlStash: HtmlStash output_formats: ClassVar[dict[Literal["xhtml", "html"], Callable[[Element], str]]] diff --git a/stubs/WebOb/webob/cachecontrol.pyi b/stubs/WebOb/webob/cachecontrol.pyi index 3a75ee38795b..bf291dc9b494 100644 --- a/stubs/WebOb/webob/cachecontrol.pyi +++ b/stubs/WebOb/webob/cachecontrol.pyi @@ -1,3 +1,4 @@ +import builtins from _typeshed import SupportsItems from collections.abc import Callable from typing import Any, Generic, Literal, overload @@ -68,7 +69,7 @@ class value_property(Generic[_T, _DefaultT, _NoneLiteral, _ScopeT]): class CacheControl(Generic[_ScopeT]): header_value: str - update_dict: type[UpdateDict] + update_dict: builtins.type[UpdateDict] properties: dict[str, Any] type: _ScopeT def __init__(self, properties: dict[str, Any], type: _ScopeT) -> None: ... diff --git a/stubs/colorful/colorful/core.pyi b/stubs/colorful/colorful/core.pyi index f0bfdf8be585..8fe0a797f7f6 100644 --- a/stubs/colorful/colorful/core.pyi +++ b/stubs/colorful/colorful/core.pyi @@ -66,7 +66,7 @@ class Colorful: def __init__(self, colormode: _ColorModeType | None = None, colorpalette: _str | _PaletteType | None = None) -> None: ... @property - def colorpalette(self) -> SupportsItems[str, str | tuple[int, int, int]] | None: ... + def colorpalette(self) -> SupportsItems[_str, _str | tuple[int, int, int]] | None: ... @colorpalette.setter def colorpalette(self, colorpalette: _str | _PaletteType) -> None: ... diff --git a/stubs/docker/docker/models/configs.pyi b/stubs/docker/docker/models/configs.pyi index d77553f4686a..3a973f31763e 100644 --- a/stubs/docker/docker/models/configs.pyi +++ b/stubs/docker/docker/models/configs.pyi @@ -1,3 +1,5 @@ +import builtins + from .resource import Collection, Model class Config(Model): @@ -10,4 +12,4 @@ class ConfigCollection(Collection[Config]): model: type[Config] def create(self, **kwargs) -> Config: ... # type: ignore[override] def get(self, config_id: str) -> Config: ... - def list(self, **kwargs) -> list[Config]: ... + def list(self, **kwargs) -> builtins.list[Config]: ... diff --git a/stubs/docker/docker/models/containers.pyi b/stubs/docker/docker/models/containers.pyi index 200bbb3baff6..14a9505d908b 100644 --- a/stubs/docker/docker/models/containers.pyi +++ b/stubs/docker/docker/models/containers.pyi @@ -1,3 +1,4 @@ +import builtins import datetime from _io import _BufferedReaderStream from collections.abc import Iterable, Iterator, Mapping @@ -163,16 +164,16 @@ class ContainerCollection(Collection[Container]): def run( self, image: str | Image, - command: str | list[str] | None = None, + command: str | builtins.list[str] | None = None, stdout: bool = True, stderr: bool = False, remove: bool = False, *, auto_remove: bool = False, - blkio_weight_device: list[ContainerWeightDevice] | None = None, + blkio_weight_device: builtins.list[ContainerWeightDevice] | None = None, blkio_weight: int | None = None, - cap_add: list[str] | None = None, - cap_drop: list[str] | None = None, + cap_add: builtins.list[str] | None = None, + cap_drop: builtins.list[str] | None = None, cgroup_parent: str | None = None, cgroupns: Literal["private", "host"] | None = None, cpu_count: int | None = None, @@ -185,19 +186,19 @@ class ContainerCollection(Collection[Container]): cpuset_cpus: str | None = None, cpuset_mems: str | None = None, detach: Literal[False] = False, - device_cgroup_rules: list[str] | None = None, - device_read_bps: list[Mapping[str, str | int]] | None = None, - device_read_iops: list[Mapping[str, str | int]] | None = None, - device_write_bps: list[Mapping[str, str | int]] | None = None, - device_write_iops: list[Mapping[str, str | int]] | None = None, - devices: list[str] | None = None, - device_requests: list[DeviceRequest] | None = None, - dns: list[str] | None = None, - dns_opt: list[str] | None = None, - dns_search: list[str] | None = None, - domainname: str | list[str] | None = None, - entrypoint: str | list[str] | None = None, - environment: dict[str, str] | list[str] | None = None, + device_cgroup_rules: builtins.list[str] | None = None, + device_read_bps: builtins.list[Mapping[str, str | int]] | None = None, + device_read_iops: builtins.list[Mapping[str, str | int]] | None = None, + device_write_bps: builtins.list[Mapping[str, str | int]] | None = None, + device_write_iops: builtins.list[Mapping[str, str | int]] | None = None, + devices: builtins.list[str] | None = None, + device_requests: builtins.list[DeviceRequest] | None = None, + dns: builtins.list[str] | None = None, + dns_opt: builtins.list[str] | None = None, + dns_search: builtins.list[str] | None = None, + domainname: str | builtins.list[str] | None = None, + entrypoint: str | builtins.list[str] | None = None, + environment: dict[str, str] | builtins.list[str] | None = None, extra_hosts: dict[str, str] | None = None, group_add: Iterable[str | int] | None = None, healthcheck: dict[str, Any] | None = None, @@ -207,7 +208,7 @@ class ContainerCollection(Collection[Container]): ipc_mode: str | None = None, isolation: str | None = None, kernel_memory: str | int | None = None, - labels: dict[str, str] | list[str] | None = None, + labels: dict[str, str] | builtins.list[str] | None = None, links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None, log_config: LogConfig | None = None, lxc_conf: dict[str, str] | None = None, @@ -216,7 +217,7 @@ class ContainerCollection(Collection[Container]): mem_reservation: str | int | None = None, mem_swappiness: int | None = None, memswap_limit: str | int | None = None, - mounts: list[Mount] | None = None, + mounts: builtins.list[Mount] | None = None, name: str | None = None, nano_cpus: int | None = None, network: str | None = None, @@ -228,13 +229,13 @@ class ContainerCollection(Collection[Container]): pid_mode: str | None = None, pids_limit: int | None = None, platform: str | None = None, - ports: Mapping[str, int | list[int] | tuple[str, int] | None] | None = None, + ports: Mapping[str, int | builtins.list[int] | tuple[str, int] | None] | None = None, privileged: bool = False, publish_all_ports: bool = False, read_only: bool | None = None, restart_policy: _RestartPolicy | None = None, runtime: str | None = None, - security_opt: list[str] | None = None, + security_opt: builtins.list[str] | None = None, shm_size: str | int | None = None, stdin_open: bool = False, stop_signal: str | None = None, @@ -243,31 +244,31 @@ class ContainerCollection(Collection[Container]): sysctls: dict[str, str] | None = None, tmpfs: dict[str, str] | None = None, tty: bool = False, - ulimits: list[Ulimit] | None = None, + ulimits: builtins.list[Ulimit] | None = None, use_config_proxy: bool | None = None, user: str | int | None = None, userns_mode: str | None = None, uts_mode: str | None = None, version: str | None = None, volume_driver: str | None = None, - volumes: dict[str, dict[str, str]] | list[str] | None = None, - volumes_from: list[str] | None = None, + volumes: dict[str, dict[str, str]] | builtins.list[str] | None = None, + volumes_from: builtins.list[str] | None = None, working_dir: str | None = None, ) -> bytes: ... # TODO: This should return a stream, if `stream` is True @overload def run( self, image: str | Image, - command: str | list[str] | None = None, + command: str | builtins.list[str] | None = None, stdout: bool = True, stderr: bool = False, remove: bool = False, *, auto_remove: bool = False, - blkio_weight_device: list[ContainerWeightDevice] | None = None, + blkio_weight_device: builtins.list[ContainerWeightDevice] | None = None, blkio_weight: int | None = None, - cap_add: list[str] | None = None, - cap_drop: list[str] | None = None, + cap_add: builtins.list[str] | None = None, + cap_drop: builtins.list[str] | None = None, cgroup_parent: str | None = None, cgroupns: Literal["private", "host"] | None = None, cpu_count: int | None = None, @@ -280,19 +281,19 @@ class ContainerCollection(Collection[Container]): cpuset_cpus: str | None = None, cpuset_mems: str | None = None, detach: Literal[True], - device_cgroup_rules: list[str] | None = None, - device_read_bps: list[Mapping[str, str | int]] | None = None, - device_read_iops: list[Mapping[str, str | int]] | None = None, - device_write_bps: list[Mapping[str, str | int]] | None = None, - device_write_iops: list[Mapping[str, str | int]] | None = None, - devices: list[str] | None = None, - device_requests: list[DeviceRequest] | None = None, - dns: list[str] | None = None, - dns_opt: list[str] | None = None, - dns_search: list[str] | None = None, - domainname: str | list[str] | None = None, - entrypoint: str | list[str] | None = None, - environment: dict[str, str] | list[str] | None = None, + device_cgroup_rules: builtins.list[str] | None = None, + device_read_bps: builtins.list[Mapping[str, str | int]] | None = None, + device_read_iops: builtins.list[Mapping[str, str | int]] | None = None, + device_write_bps: builtins.list[Mapping[str, str | int]] | None = None, + device_write_iops: builtins.list[Mapping[str, str | int]] | None = None, + devices: builtins.list[str] | None = None, + device_requests: builtins.list[DeviceRequest] | None = None, + dns: builtins.list[str] | None = None, + dns_opt: builtins.list[str] | None = None, + dns_search: builtins.list[str] | None = None, + domainname: str | builtins.list[str] | None = None, + entrypoint: str | builtins.list[str] | None = None, + environment: dict[str, str] | builtins.list[str] | None = None, extra_hosts: dict[str, str] | None = None, group_add: Iterable[str | int] | None = None, healthcheck: dict[str, Any] | None = None, @@ -302,7 +303,7 @@ class ContainerCollection(Collection[Container]): ipc_mode: str | None = None, isolation: str | None = None, kernel_memory: str | int | None = None, - labels: dict[str, str] | list[str] | None = None, + labels: dict[str, str] | builtins.list[str] | None = None, links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None, log_config: LogConfig | None = None, lxc_conf: dict[str, str] | None = None, @@ -311,7 +312,7 @@ class ContainerCollection(Collection[Container]): mem_reservation: str | int | None = None, mem_swappiness: int | None = None, memswap_limit: str | int | None = None, - mounts: list[Mount] | None = None, + mounts: builtins.list[Mount] | None = None, name: str | None = None, nano_cpus: int | None = None, network: str | None = None, @@ -323,13 +324,13 @@ class ContainerCollection(Collection[Container]): pid_mode: str | None = None, pids_limit: int | None = None, platform: str | None = None, - ports: Mapping[str, int | list[int] | tuple[str, int] | None] | None = None, + ports: Mapping[str, int | builtins.list[int] | tuple[str, int] | None] | None = None, privileged: bool = False, publish_all_ports: bool = False, read_only: bool | None = None, restart_policy: _RestartPolicy | None = None, runtime: str | None = None, - security_opt: list[str] | None = None, + security_opt: builtins.list[str] | None = None, shm_size: str | int | None = None, stdin_open: bool = False, stop_signal: str | None = None, @@ -338,28 +339,28 @@ class ContainerCollection(Collection[Container]): sysctls: dict[str, str] | None = None, tmpfs: dict[str, str] | None = None, tty: bool = False, - ulimits: list[Ulimit] | None = None, + ulimits: builtins.list[Ulimit] | None = None, use_config_proxy: bool | None = None, user: str | int | None = None, userns_mode: str | None = None, uts_mode: str | None = None, version: str | None = None, volume_driver: str | None = None, - volumes: dict[str, dict[str, str]] | list[str] | None = None, - volumes_from: list[str] | None = None, + volumes: dict[str, dict[str, str]] | builtins.list[str] | None = None, + volumes_from: builtins.list[str] | None = None, working_dir: str | None = None, ) -> Container: ... def create( # type: ignore[override] self, image: str | Image, - command: str | list[str] | None = None, + command: str | builtins.list[str] | None = None, *, auto_remove: bool = False, - blkio_weight_device: list[ContainerWeightDevice] | None = None, + blkio_weight_device: builtins.list[ContainerWeightDevice] | None = None, blkio_weight: int | None = None, - cap_add: list[str] | None = None, - cap_drop: list[str] | None = None, + cap_add: builtins.list[str] | None = None, + cap_drop: builtins.list[str] | None = None, cgroup_parent: str | None = None, cgroupns: Literal["private", "host"] | None = None, cpu_count: int | None = None, @@ -372,19 +373,19 @@ class ContainerCollection(Collection[Container]): cpuset_cpus: str | None = None, cpuset_mems: str | None = None, detach: bool = False, - device_cgroup_rules: list[str] | None = None, - device_read_bps: list[Mapping[str, str | int]] | None = None, - device_read_iops: list[Mapping[str, str | int]] | None = None, - device_write_bps: list[Mapping[str, str | int]] | None = None, - device_write_iops: list[Mapping[str, str | int]] | None = None, - devices: list[str] | None = None, - device_requests: list[DeviceRequest] | None = None, - dns: list[str] | None = None, - dns_opt: list[str] | None = None, - dns_search: list[str] | None = None, - domainname: str | list[str] | None = None, - entrypoint: str | list[str] | None = None, - environment: dict[str, str] | list[str] | None = None, + device_cgroup_rules: builtins.list[str] | None = None, + device_read_bps: builtins.list[Mapping[str, str | int]] | None = None, + device_read_iops: builtins.list[Mapping[str, str | int]] | None = None, + device_write_bps: builtins.list[Mapping[str, str | int]] | None = None, + device_write_iops: builtins.list[Mapping[str, str | int]] | None = None, + devices: builtins.list[str] | None = None, + device_requests: builtins.list[DeviceRequest] | None = None, + dns: builtins.list[str] | None = None, + dns_opt: builtins.list[str] | None = None, + dns_search: builtins.list[str] | None = None, + domainname: str | builtins.list[str] | None = None, + entrypoint: str | builtins.list[str] | None = None, + environment: dict[str, str] | builtins.list[str] | None = None, extra_hosts: dict[str, str] | None = None, group_add: Iterable[str | int] | None = None, healthcheck: dict[str, Any] | None = None, @@ -394,7 +395,7 @@ class ContainerCollection(Collection[Container]): ipc_mode: str | None = None, isolation: str | None = None, kernel_memory: str | int | None = None, - labels: dict[str, str] | list[str] | None = None, + labels: dict[str, str] | builtins.list[str] | None = None, links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None, log_config: LogConfig | None = None, lxc_conf: dict[str, str] | None = None, @@ -403,7 +404,7 @@ class ContainerCollection(Collection[Container]): mem_reservation: str | int | None = None, mem_swappiness: int | None = None, memswap_limit: str | int | None = None, - mounts: list[Mount] | None = None, + mounts: builtins.list[Mount] | None = None, name: str | None = None, nano_cpus: int | None = None, network: str | None = None, @@ -415,13 +416,13 @@ class ContainerCollection(Collection[Container]): pid_mode: str | None = None, pids_limit: int | None = None, platform: str | None = None, - ports: Mapping[str, int | list[int] | tuple[str, int] | None] | None = None, + ports: Mapping[str, int | builtins.list[int] | tuple[str, int] | None] | None = None, privileged: bool = False, publish_all_ports: bool = False, read_only: bool | None = None, restart_policy: _RestartPolicy | None = None, runtime: str | None = None, - security_opt: list[str] | None = None, + security_opt: builtins.list[str] | None = None, shm_size: str | int | None = None, stdin_open: bool = False, stop_signal: str | None = None, @@ -430,15 +431,15 @@ class ContainerCollection(Collection[Container]): sysctls: dict[str, str] | None = None, tmpfs: dict[str, str] | None = None, tty: bool = False, - ulimits: list[Ulimit] | None = None, + ulimits: builtins.list[Ulimit] | None = None, use_config_proxy: bool | None = None, user: str | int | None = None, userns_mode: str | None = None, uts_mode: str | None = None, version: str | None = None, volume_driver: str | None = None, - volumes: dict[str, dict[str, str]] | list[str] | None = None, - volumes_from: list[str] | None = None, + volumes: dict[str, dict[str, str]] | builtins.list[str] | None = None, + volumes_from: builtins.list[str] | None = None, working_dir: str | None = None, ) -> Container: ... def get(self, container_id: str) -> Container: ... @@ -446,12 +447,12 @@ class ContainerCollection(Collection[Container]): self, all: bool = False, before: str | None = None, - filters: dict[str, str | list[str] | bool] | None = None, + filters: dict[str, str | builtins.list[str] | bool] | None = None, limit: int = -1, since: str | None = None, sparse: bool = False, ignore_removed: bool = False, - ) -> list[Container]: ... + ) -> builtins.list[Container]: ... def prune(self, filters: dict[str, Any] | None = None) -> dict[str, Any]: ... RUN_CREATE_KWARGS: list[str] diff --git a/stubs/docker/docker/models/images.pyi b/stubs/docker/docker/models/images.pyi index 8bdd6808583a..7f42c3fa8460 100644 --- a/stubs/docker/docker/models/images.pyi +++ b/stubs/docker/docker/models/images.pyi @@ -1,3 +1,4 @@ +import builtins from _typeshed import SupportsRead from collections.abc import Iterator from io import StringIO @@ -61,11 +62,11 @@ class ImageCollection(Collection[Image]): shmsize: int | None = None, labels: dict[str, Any] | None = None, # need to use list, because the type must be json serializable - cache_from: list[str] | None = None, + cache_from: builtins.list[str] | None = None, target: str | None = None, network_mode: str | None = None, squash: bool | None = None, - extra_hosts: list[str] | dict[str, str] | None = None, + extra_hosts: builtins.list[str] | dict[str, str] | None = None, platform: str | None = None, isolation: str | None = None, use_config_proxy: bool = True, diff --git a/stubs/docker/docker/models/networks.pyi b/stubs/docker/docker/models/networks.pyi index d3405666a581..68a31333d99a 100644 --- a/stubs/docker/docker/models/networks.pyi +++ b/stubs/docker/docker/models/networks.pyi @@ -1,3 +1,4 @@ +import builtins from typing import Any, Literal from docker.types import IPAMConfig @@ -33,5 +34,5 @@ class NetworkCollection(Collection[Network]): def get( self, network_id: str, verbose: bool | None = None, scope: Literal["local", "global", "swarm"] | None = None ) -> Network: ... # type: ignore[override] - def list(self, *args, **kwargs) -> list[Network]: ... + def list(self, *args, **kwargs) -> builtins.list[Network]: ... def prune(self, filters: dict[str, Any] | None = None) -> dict[str, Any]: ... diff --git a/stubs/docker/docker/models/resource.pyi b/stubs/docker/docker/models/resource.pyi index 8f81f52301b9..1d739c5fe4a1 100644 --- a/stubs/docker/docker/models/resource.pyi +++ b/stubs/docker/docker/models/resource.pyi @@ -1,3 +1,4 @@ +import builtins from typing import Any, Generic, NoReturn, TypeVar from typing_extensions import Self @@ -26,7 +27,7 @@ class Collection(Generic[_T]): client: DockerClient def __init__(self, client: DockerClient | None = None) -> None: ... def __call__(self, *args, **kwargs) -> NoReturn: ... - def list(self) -> list[_T]: ... + def list(self) -> builtins.list[_T]: ... def get(self, key: str) -> _T: ... def create(self, attrs: Any | None = None) -> _T: ... def prepare_model(self, attrs: Model | dict[str, Any]) -> _T: ... diff --git a/stubs/docker/docker/models/volumes.pyi b/stubs/docker/docker/models/volumes.pyi index 29b9c124c902..2226dc844130 100644 --- a/stubs/docker/docker/models/volumes.pyi +++ b/stubs/docker/docker/models/volumes.pyi @@ -1,3 +1,4 @@ +import builtins from typing import Any from .resource import Collection, Model @@ -12,5 +13,5 @@ class VolumeCollection(Collection[Volume]): model: type[Volume] def create(self, name: str | None = None, **kwargs) -> Volume: ... # type: ignore[override] def get(self, volume_id: str) -> Volume: ... - def list(self, **kwargs) -> list[Volume]: ... + def list(self, **kwargs) -> builtins.list[Volume]: ... def prune(self, filters: dict[str, Any] | None = None) -> dict[str, Any]: ... diff --git a/stubs/docker/docker/types/containers.pyi b/stubs/docker/docker/types/containers.pyi index b6ce4f4f1c64..0c9c177e30b5 100644 --- a/stubs/docker/docker/types/containers.pyi +++ b/stubs/docker/docker/types/containers.pyi @@ -1,3 +1,4 @@ +import builtins from collections.abc import Iterable, Mapping from typing import Any, Final, Literal @@ -18,7 +19,7 @@ class LogConfigTypesEnum: NONE: Final = "none" class LogConfig(DictType[Any]): - types: type[LogConfigTypesEnum] + types: builtins.type[LogConfigTypesEnum] def __init__( self, *, type: str = ..., Type: str = ..., config: dict[str, str] = ..., Config: dict[str, str] = ... ) -> None: ... diff --git a/stubs/docutils/docutils/nodes.pyi b/stubs/docutils/docutils/nodes.pyi index f01429cb3e19..d40fbed7cd19 100644 --- a/stubs/docutils/docutils/nodes.pyi +++ b/stubs/docutils/docutils/nodes.pyi @@ -37,9 +37,9 @@ class Node: line: int | None @property - def document(self) -> document | None: ... + def document(self) -> _Document | None: ... @document.setter - def document(self, value: document) -> None: ... + def document(self, value: _Document) -> None: ... def __bool__(self) -> Literal[True]: ... def asdom( diff --git a/stubs/ephem/ephem/_libastro.pyi b/stubs/ephem/ephem/_libastro.pyi index 0360fdcf4265..1501df7a3b4d 100644 --- a/stubs/ephem/ephem/_libastro.pyi +++ b/stubs/ephem/ephem/_libastro.pyi @@ -1,3 +1,4 @@ +import builtins from _typeshed import Unused from datetime import datetime as _datetime from typing import Final, NoReturn, TypeAlias, TypedDict, overload, type_check_only @@ -77,8 +78,8 @@ class Date(float): @overload def __new__(cls, date: _DateInitType, /) -> Date: ... - def triple(self) -> tuple[int, int, float]: ... - def tuple(self) -> tuple[int, int, int, int, int, float]: ... + def triple(self) -> builtins.tuple[int, int, float]: ... + def tuple(self) -> builtins.tuple[int, int, int, int, int, float]: ... def datetime(self) -> _datetime: ... @disjoint_base diff --git a/stubs/httplib2/httplib2/__init__.pyi b/stubs/httplib2/httplib2/__init__.pyi index 2c03f0f50535..0961d41d6f6c 100644 --- a/stubs/httplib2/httplib2/__init__.pyi +++ b/stubs/httplib2/httplib2/__init__.pyi @@ -1,3 +1,4 @@ +import builtins import email.message import http.client import re @@ -197,7 +198,7 @@ class Response(dict[str, str | _T]): status: int reason: str previous: Response[_T] | None - def __init__(self, info: http.client.HTTPResponse | email.message.Message | dict[str, _T]) -> None: ... + def __init__(self, info: http.client.HTTPResponse | email.message.Message | builtins.dict[str, _T]) -> None: ... @property def dict(self) -> Self: ... diff --git a/stubs/peewee/peewee.pyi b/stubs/peewee/peewee.pyi index a529040e5081..d0d887816807 100644 --- a/stubs/peewee/peewee.pyi +++ b/stubs/peewee/peewee.pyi @@ -5,7 +5,7 @@ from collections.abc import Callable, Generator, Iterable, Iterator from datetime import date, datetime, time from decimal import Decimal from types import TracebackType -from typing import Any, ClassVar, Final, Generic, Literal, NamedTuple, NoReturn, TypedDict, overload, type_check_only +from typing import Any, ClassVar, Final, Generic, Literal, NamedTuple, NoReturn, TypeAlias, TypedDict, overload, type_check_only from typing_extensions import Self, TypeIs, TypeVar, Unpack from uuid import UUID @@ -18,6 +18,7 @@ def reraise(tp: Unused, value: BaseException, tb: TracebackType | None = None) - _T = TypeVar("_T") _VT = TypeVar("_VT") _F = TypeVar("_F", bound=Callable[..., Any]) +_Model: TypeAlias = Model _M = TypeVar("_M", bound=Model, default=Model) # __get__/__set__ value type. Bare Field defaults to Field[Any]. _V = TypeVar("_V", default=Any) @@ -104,7 +105,7 @@ class DatabaseProxy(Proxy): def transaction(self, *args, **kwargs) -> _transaction: ... def savepoint(self) -> _savepoint: ... @property - def Model(self) -> type[Model]: ... + def Model(self) -> type[_Model]: ... class ModelDescriptor: ... @@ -870,20 +871,20 @@ class Database(_callable_context_manager): def get_primary_keys(self, table, schema: str | None = None): ... def get_foreign_keys(self, table, schema: str | None = None) -> list[ForeignKeyMetadata]: ... def sequence_exists(self, seq) -> bool: ... - def create_tables(self, models: Iterable[type[Model]], **options) -> None: ... - def drop_tables(self, models: Iterable[type[Model]], **kwargs) -> None: ... + def create_tables(self, models: Iterable[type[_Model]], **options) -> None: ... + def drop_tables(self, models: Iterable[type[_Model]], **kwargs) -> None: ... def extract_date(self, date_part, date_field): ... def truncate_date(self, date_part, date_field): ... def to_timestamp(self, date_field): ... def from_timestamp(self, date_field): ... def random(self): ... - def bind(self, models: Iterable[type[Model]], bind_refs: bool = True, bind_backrefs: bool = True) -> None: ... + def bind(self, models: Iterable[type[_Model]], bind_refs: bool = True, bind_backrefs: bool = True) -> None: ... def bind_ctx( - self, models: Iterable[type[Model]], bind_refs: bool = True, bind_backrefs: bool = True + self, models: Iterable[type[_Model]], bind_refs: bool = True, bind_backrefs: bool = True ) -> _BoundModelsContext: ... def get_noop_select(self, ctx): ... @property - def Model(self) -> type[Model]: ... + def Model(self) -> type[_Model]: ... class SqliteDatabase(Database): field_types: Incomplete diff --git a/stubs/pika/pika/spec.pyi b/stubs/pika/pika/spec.pyi index ef1d13c3a69f..8ce6fb2e2adb 100644 --- a/stubs/pika/pika/spec.pyi +++ b/stubs/pika/pika/spec.pyi @@ -816,7 +816,7 @@ class Confirm(Class): def encode(self) -> list[bytes]: ... class BasicProperties(Properties): - CLASS: ClassVar[type[Basic]] + CLASS: ClassVar[builtins.type[Basic]] INDEX: ClassVar[int] FLAG_CONTENT_TYPE: ClassVar[int] FLAG_CONTENT_ENCODING: ClassVar[int] diff --git a/stubs/psycopg2/psycopg2/_psycopg.pyi b/stubs/psycopg2/psycopg2/_psycopg.pyi index 1461bbc002e5..c40c83048a6e 100644 --- a/stubs/psycopg2/psycopg2/_psycopg.pyi +++ b/stubs/psycopg2/psycopg2/_psycopg.pyi @@ -424,6 +424,7 @@ class Xid: def __len__(self) -> int: ... _T_cur = TypeVar("_T_cur", bound=cursor) +_Lobject: TypeAlias = lobject @disjoint_base class connection: @@ -444,7 +445,7 @@ class connection: def binary_types(self) -> dict[Incomplete, Incomplete]: ... @property def closed(self) -> int: ... - cursor_factory: Callable[[connection, str | bytes | None], cursor] + cursor_factory: Callable[[connection, str | bytes | None], _Cursor] @property def dsn(self) -> str: ... @property @@ -490,7 +491,7 @@ class connection: @overload def cursor( self, name: str | bytes | None = None, cursor_factory: None = None, withhold: bool = False, scrollable: bool | None = None - ) -> cursor: ... + ) -> _Cursor: ... @overload def cursor( self, @@ -522,8 +523,8 @@ class connection: mode: str | None = ..., new_oid: int = ..., new_file: str | None = ..., - lobject_factory: type[lobject] = ..., - ) -> lobject: ... + lobject_factory: type[_Lobject] = ..., + ) -> _Lobject: ... def poll(self) -> int: ... def reset(self) -> None: ... def rollback(self) -> None: ... diff --git a/stubs/pyluach/pyluach/dates.pyi b/stubs/pyluach/pyluach/dates.pyi index 479c4b53be35..3cc936a8c592 100644 --- a/stubs/pyluach/pyluach/dates.pyi +++ b/stubs/pyluach/pyluach/dates.pyi @@ -1,4 +1,5 @@ import abc +import builtins import datetime from collections.abc import Generator from enum import Enum @@ -51,7 +52,7 @@ class CalendarDateMixin: day: int def __init__(self, year: int, month: int, day: int, jd: float | None = None) -> None: ... def __iter__(self) -> Generator[int]: ... - def tuple(self) -> tuple[int, int, int]: ... + def tuple(self) -> builtins.tuple[int, int, int]: ... def dict(self) -> _DateDict: ... def replace(self, year: int | None = None, month: int | None = None, day: int | None = None) -> Self: ... diff --git a/stubs/pynput/pynput/keyboard/_base.pyi b/stubs/pynput/pynput/keyboard/_base.pyi index a30a70814ed5..fee88c0135dd 100644 --- a/stubs/pynput/pynput/keyboard/_base.pyi +++ b/stubs/pynput/pynput/keyboard/_base.pyi @@ -1,3 +1,4 @@ +import builtins import contextlib import enum import sys @@ -95,8 +96,8 @@ class Key(enum.Enum): scroll_lock = cast(KeyCode, ...) class Controller: - _KeyCode: ClassVar[type[KeyCode]] # undocumented - _Key: ClassVar[type[Key]] # undocumented + _KeyCode: ClassVar[builtins.type[KeyCode]] # undocumented + _Key: ClassVar[builtins.type[Key]] # undocumented if sys.platform == "linux": CTRL_MASK: ClassVar[int] diff --git a/stubs/pyserial/serial/urlhandler/protocol_loop.pyi b/stubs/pyserial/serial/urlhandler/protocol_loop.pyi index 0a262b0fd115..97db0d4dfcf1 100644 --- a/stubs/pyserial/serial/urlhandler/protocol_loop.pyi +++ b/stubs/pyserial/serial/urlhandler/protocol_loop.pyi @@ -1,5 +1,5 @@ import logging -import queue +import queue as _queue from _typeshed import ReadableBuffer from serial.serialutil import SerialBase @@ -8,7 +8,7 @@ LOGGER_LEVELS: dict[str, int] class Serial(SerialBase): buffer_size: int - queue: queue.Queue[bytes | None] | None + queue: _queue.Queue[bytes | None] | None logger: logging.Logger | None def open(self) -> None: ... def from_url(self, url: str) -> None: ... diff --git a/stubs/python-xlib/Xlib/protocol/rq.pyi b/stubs/python-xlib/Xlib/protocol/rq.pyi index af22cf3d0b34..1c89b6964ed0 100644 --- a/stubs/python-xlib/Xlib/protocol/rq.pyi +++ b/stubs/python-xlib/Xlib/protocol/rq.pyi @@ -205,7 +205,7 @@ class String16(ValueField): class List(ValueField): structcode: None - type: Struct | ScalarObj | ResourceObj | ClassInfoClass | type[ValueField] + type: Struct | ScalarObj | ResourceObj | ClassInfoClass | Type[ValueField] pad: int def __init__( self, name: str, type: Struct | ScalarObj | ResourceObj | ClassInfoClass | Type[ValueField], pad: int = 1 diff --git a/stubs/reportlab/reportlab/lib/utils.pyi b/stubs/reportlab/reportlab/lib/utils.pyi index 4667000e227d..6ea6a6d1ea32 100644 --- a/stubs/reportlab/reportlab/lib/utils.pyi +++ b/stubs/reportlab/reportlab/lib/utils.pyi @@ -1,4 +1,4 @@ -import datetime +import datetime as _datetime import zipimport from _typeshed import Incomplete, SupportsItems from builtins import _ClassInfo @@ -178,11 +178,11 @@ class RLString(str): def makeFileName(s): ... -class FixedOffsetTZ(datetime.tzinfo): +class FixedOffsetTZ(_datetime.tzinfo): def __init__(self, h: float, m: float, name: str | None) -> None: ... - def utcoffset(self, dt: datetime.datetime | None) -> datetime.timedelta: ... - def tzname(self, dt: datetime.datetime | None) -> str | None: ... - def dst(self, dt: datetime.datetime | None) -> datetime.timedelta: ... + def utcoffset(self, dt: _datetime.datetime | None) -> _datetime.timedelta: ... + def tzname(self, dt: _datetime.datetime | None) -> str | None: ... + def dst(self, dt: _datetime.datetime | None) -> _datetime.timedelta: ... class TimeStamp: tzname: str @@ -193,7 +193,7 @@ class TimeStamp: dmm: int def __init__(self, invariant: int | bool | None = None) -> None: ... @property - def datetime(self) -> datetime.datetime: ... + def datetime(self) -> _datetime.datetime: ... @property def asctime(self) -> str: ... diff --git a/stubs/reportlab/reportlab/platypus/doctemplate.pyi b/stubs/reportlab/reportlab/platypus/doctemplate.pyi index bdafbd35c529..328125f42bae 100644 --- a/stubs/reportlab/reportlab/platypus/doctemplate.pyi +++ b/stubs/reportlab/reportlab/platypus/doctemplate.pyi @@ -165,6 +165,8 @@ class onDrawStr(str): ) -> Self: ... def __getnewargs__(self) -> tuple[str, Callable[[Canvas, str | None, str], object], str, str | None]: ... # type: ignore[override] +_OnDrawStr: TypeAlias = onDrawStr + class PageAccumulator: name: str data: list[tuple[Any, ...]] @@ -177,7 +179,7 @@ class PageAccumulator: def onPage(self, canv: Canvas, doc: BaseDocTemplate) -> None: ... def onPageEnd(self, canv: Canvas, doc: BaseDocTemplate) -> None: ... def pageEndAction(self, canv: Canvas, doc: BaseDocTemplate) -> None: ... - def onDrawStr(self, value: object, *args) -> onDrawStr: ... + def onDrawStr(self, value: object, *args) -> _OnDrawStr: ... class BaseDocTemplate: filename: Incomplete diff --git a/stubs/requests/requests/sessions.pyi b/stubs/requests/requests/sessions.pyi index fb9c618b50aa..fc21257ed706 100644 --- a/stubs/requests/requests/sessions.pyi +++ b/stubs/requests/requests/sessions.pyi @@ -130,7 +130,7 @@ class Session(SessionRedirectMixin): max_redirects: int trust_env: bool cookies: RequestsCookieJar - adapters: MutableMapping[str, adapters.BaseAdapter] + adapters: MutableMapping[str, _BaseAdapter] def __init__(self) -> None: ... def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... diff --git a/stubs/tensorflow/tensorflow/__init__.pyi b/stubs/tensorflow/tensorflow/__init__.pyi index 23e62c413dab..d4cf842f817f 100644 --- a/stubs/tensorflow/tensorflow/__init__.pyi +++ b/stubs/tensorflow/tensorflow/__init__.pyi @@ -6,7 +6,7 @@ from collections.abc import Callable, Generator, Iterable, Iterator, Sequence from contextlib import contextmanager from enum import Enum from types import TracebackType -from typing import Any, Generic, Literal, ParamSpec, TypeVar, overload +from typing import Any, Generic, Literal, ParamSpec, TypeAlias, TypeVar, overload from typing_extensions import Self from google.protobuf.message import Message @@ -284,13 +284,14 @@ class name_scope(metaclass=abc.ABCMeta): _P = ParamSpec("_P") _R = TypeVar("_R") +_NameScope: TypeAlias = name_scope class Module(AutoTrackable): def __init__(self, name: str | None = None) -> None: ... @property def name(self) -> str: ... @property - def name_scope(self) -> name_scope: ... + def name_scope(self) -> _NameScope: ... # Documentation only specifies these as returning Sequence. Actual # implementation does tuple. @property