diff --git a/mypy/typeshed/stdlib/_decimal.pyi b/mypy/typeshed/stdlib/_decimal.pyi index cdd0268a1bdf..06c0197dcf07 100644 --- a/mypy/typeshed/stdlib/_decimal.pyi +++ b/mypy/typeshed/stdlib/_decimal.pyi @@ -27,14 +27,14 @@ _TrapType: TypeAlias = type[DecimalException] __version__: Final[str] __libmpdec_version__: Final[str] -ROUND_DOWN: Final[str] -ROUND_HALF_UP: Final[str] -ROUND_HALF_EVEN: Final[str] -ROUND_CEILING: Final[str] -ROUND_FLOOR: Final[str] -ROUND_UP: Final[str] -ROUND_HALF_DOWN: Final[str] -ROUND_05UP: Final[str] +ROUND_DOWN: Final = "ROUND_DOWN" +ROUND_HALF_UP: Final = "ROUND_HALF_UP" +ROUND_HALF_EVEN: Final = "ROUND_HALF_EVEN" +ROUND_CEILING: Final = "ROUND_CEILING" +ROUND_FLOOR: Final = "ROUND_FLOOR" +ROUND_UP: Final = "ROUND_UP" +ROUND_HALF_DOWN: Final = "ROUND_HALF_DOWN" +ROUND_05UP: Final = "ROUND_05UP" HAVE_CONTEXTVAR: Final[bool] HAVE_THREADS: Final[bool] MAX_EMAX: Final[int] diff --git a/mypy/typeshed/stdlib/_socket.pyi b/mypy/typeshed/stdlib/_socket.pyi index 4cf71cbcadfa..9be0c3f2e669 100644 --- a/mypy/typeshed/stdlib/_socket.pyi +++ b/mypy/typeshed/stdlib/_socket.pyi @@ -78,7 +78,7 @@ if sys.platform == "win32": SO_EXCLUSIVEADDRUSE: int if sys.platform != "win32": SO_REUSEPORT: int - if sys.platform != "darwin" or sys.version_info >= (3, 13): + if sys.platform != "darwin": SO_BINDTODEVICE: int if sys.platform != "win32" and sys.platform != "darwin": diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi index b9652ec5f75a..029bfeefe4b3 100644 --- a/mypy/typeshed/stdlib/argparse.pyi +++ b/mypy/typeshed/stdlib/argparse.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsWrite, sentinel from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern -from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload +from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload from typing_extensions import Self, TypeAlias, deprecated __all__ = [ @@ -33,25 +33,14 @@ _ActionT = TypeVar("_ActionT", bound=Action) _ArgumentParserT = TypeVar("_ArgumentParserT", bound=ArgumentParser) _N = TypeVar("_N") _ActionType: TypeAlias = Callable[[str], Any] | FileType | str -# more precisely, Literal["store", "store_const", "store_true", -# "store_false", "append", "append_const", "count", "help", "version", -# "extend"], but using this would make it hard to annotate callers -# that don't use a literal argument -_ActionStr: TypeAlias = str -# more precisely, Literal["?", "*", "+", "...", "A...", -# "==SUPPRESS=="], but using this would make it hard to annotate -# callers that don't use a literal argument -_NArgsStr: TypeAlias = str ONE_OR_MORE: Final = "+" OPTIONAL: Final = "?" PARSER: Final = "A..." REMAINDER: Final = "..." -_SUPPRESS_T = NewType("_SUPPRESS_T", str) -SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is -# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy +SUPPRESS: Final = "==SUPPRESS==" ZERO_OR_MORE: Final = "*" -_UNRECOGNIZED_ARGS_ATTR: Final[str] # undocumented +_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented class ArgumentError(Exception): argument_name: str | None @@ -86,8 +75,13 @@ class _ActionsContainer: def add_argument( self, *name_or_flags: str, - action: _ActionStr | type[Action] = ..., - nargs: int | _NArgsStr | _SUPPRESS_T | None = None, + # str covers predefined actions ("store_true", "count", etc.) + # and user registered actions via the `register` method. + action: str | type[Action] = ..., + # more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="], + # but using this would make it hard to annotate callers that don't use a + # literal argument and for subclasses to override this method. + nargs: int | str | None = None, const: Any = ..., default: Any = ..., type: _ActionType = ..., diff --git a/mypy/typeshed/stdlib/asyncio/tasks.pyi b/mypy/typeshed/stdlib/asyncio/tasks.pyi index a349e81d80e9..f6ee109915e0 100644 --- a/mypy/typeshed/stdlib/asyncio/tasks.pyi +++ b/mypy/typeshed/stdlib/asyncio/tasks.pyi @@ -79,6 +79,7 @@ if sys.version_info >= (3, 12): _FutureLike: TypeAlias = Future[_T] | Awaitable[_T] else: _FutureLike: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T] + _TaskYieldType: TypeAlias = Future[object] | None FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED @@ -347,7 +348,8 @@ else: *coros_or_futures: _FutureLike[_T], loop: AbstractEventLoop | None = None, return_exceptions: bool ) -> Future[list[_T | BaseException]]: ... -def run_coroutine_threadsafe(coro: _FutureLike[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ... +# unlike some asyncio apis, This does strict runtime checking of actually being a coroutine, not of any future-like. +def run_coroutine_threadsafe(coro: Coroutine[Any, Any, _T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ... if sys.version_info >= (3, 10): def shield(arg: _FutureLike[_T]) -> Future[_T]: ... diff --git a/mypy/typeshed/stdlib/bdb.pyi b/mypy/typeshed/stdlib/bdb.pyi index 75bfa91cc379..2004874a52b2 100644 --- a/mypy/typeshed/stdlib/bdb.pyi +++ b/mypy/typeshed/stdlib/bdb.pyi @@ -1,6 +1,7 @@ import sys from _typeshed import ExcInfo, TraceFunction, Unused -from collections.abc import Callable, Iterable, Mapping +from collections.abc import Callable, Iterable, Iterator, Mapping +from contextlib import contextmanager from types import CodeType, FrameType, TracebackType from typing import IO, Any, Final, SupportsInt, TypeVar from typing_extensions import ParamSpec @@ -30,6 +31,10 @@ class Bdb: def __init__(self, skip: Iterable[str] | None = None) -> None: ... def canonic(self, filename: str) -> str: ... def reset(self) -> None: ... + if sys.version_info >= (3, 12): + @contextmanager + def set_enterframe(self, frame: FrameType) -> Iterator[None]: ... + def trace_dispatch(self, frame: FrameType, event: str, arg: Any) -> TraceFunction: ... def dispatch_line(self, frame: FrameType) -> TraceFunction: ... def dispatch_call(self, frame: FrameType, arg: None) -> TraceFunction: ... @@ -73,7 +78,7 @@ class Bdb: def get_file_breaks(self, filename: str) -> list[Breakpoint]: ... def get_all_breaks(self) -> list[Breakpoint]: ... def get_stack(self, f: FrameType | None, t: TracebackType | None) -> tuple[list[tuple[FrameType, int]], int]: ... - def format_stack_entry(self, frame_lineno: int, lprefix: str = ": ") -> str: ... + def format_stack_entry(self, frame_lineno: tuple[FrameType, int], lprefix: str = ": ") -> str: ... def run( self, cmd: str | CodeType, globals: dict[str, Any] | None = None, locals: Mapping[str, Any] | None = None ) -> None: ... diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 6fb901b9f009..c278707c273f 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -1197,7 +1197,7 @@ def ascii(obj: object, /) -> str: ... def bin(number: int | SupportsIndex, /) -> str: ... def breakpoint(*args: Any, **kws: Any) -> None: ... def callable(obj: object, /) -> TypeIs[Callable[..., object]]: ... -def chr(i: int, /) -> str: ... +def chr(i: int | SupportsIndex, /) -> str: ... # We define this here instead of using os.PathLike to avoid import cycle issues. # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 diff --git a/mypy/typeshed/stdlib/cmath.pyi b/mypy/typeshed/stdlib/cmath.pyi index fab9d10230f8..a08addcf5438 100644 --- a/mypy/typeshed/stdlib/cmath.pyi +++ b/mypy/typeshed/stdlib/cmath.pyi @@ -1,13 +1,13 @@ -from typing import SupportsComplex, SupportsFloat, SupportsIndex +from typing import Final, SupportsComplex, SupportsFloat, SupportsIndex from typing_extensions import TypeAlias -e: float -pi: float -inf: float -infj: complex -nan: float -nanj: complex -tau: float +e: Final[float] +pi: Final[float] +inf: Final[float] +infj: Final[complex] +nan: Final[float] +nanj: Final[complex] +tau: Final[float] _C: TypeAlias = SupportsFloat | SupportsComplex | SupportsIndex | complex diff --git a/mypy/typeshed/stdlib/decimal.pyi b/mypy/typeshed/stdlib/decimal.pyi index 7eb922c8a7ed..4ded21e0b017 100644 --- a/mypy/typeshed/stdlib/decimal.pyi +++ b/mypy/typeshed/stdlib/decimal.pyi @@ -65,7 +65,7 @@ class Underflow(Inexact, Rounded, Subnormal): ... class FloatOperation(DecimalException, TypeError): ... class Decimal: - def __new__(cls, value: _DecimalNew = ..., context: Context | None = ...) -> Self: ... + def __new__(cls, value: _DecimalNew = "0", context: Context | None = None) -> Self: ... @classmethod def from_float(cls, f: float, /) -> Self: ... def __bool__(self) -> bool: ... @@ -163,12 +163,12 @@ class Decimal: def __reduce__(self) -> tuple[type[Self], tuple[str]]: ... def __copy__(self) -> Self: ... def __deepcopy__(self, memo: Any, /) -> Self: ... - def __format__(self, specifier: str, context: Context | None = ..., /) -> str: ... + def __format__(self, specifier: str, context: Context | None = None, /) -> str: ... class Context: # TODO: Context doesn't allow you to delete *any* attributes from instances of the class at runtime, # even settable attributes like `prec` and `rounding`, - # but that's inexpressable in the stub. + # but that's inexpressible in the stub. # Type checkers either ignore it or misinterpret it # if you add a `def __delattr__(self, name: str, /) -> NoReturn` method to the stub prec: int @@ -181,14 +181,14 @@ class Context: flags: dict[_TrapType, bool] def __init__( self, - prec: int | None = ..., - rounding: str | None = ..., - Emin: int | None = ..., - Emax: int | None = ..., - capitals: int | None = ..., - clamp: int | None = ..., - flags: None | dict[_TrapType, bool] | Container[_TrapType] = ..., - traps: None | dict[_TrapType, bool] | Container[_TrapType] = ..., + prec: int | None = None, + rounding: str | None = None, + Emin: int | None = None, + Emax: int | None = None, + capitals: int | None = None, + clamp: int | None = None, + flags: dict[_TrapType, bool] | Container[_TrapType] | None = None, + traps: dict[_TrapType, bool] | Container[_TrapType] | None = None, ) -> None: ... def __reduce__(self) -> tuple[type[Self], tuple[Any, ...]]: ... def clear_flags(self) -> None: ... diff --git a/mypy/typeshed/stdlib/email/_header_value_parser.pyi b/mypy/typeshed/stdlib/email/_header_value_parser.pyi index ff405a8b61d2..a4c2d8b1a92e 100644 --- a/mypy/typeshed/stdlib/email/_header_value_parser.pyi +++ b/mypy/typeshed/stdlib/email/_header_value_parser.pyi @@ -1,3 +1,4 @@ +import sys from collections.abc import Iterable, Iterator from email.errors import HeaderParseError, MessageDefect from email.policy import Policy @@ -21,6 +22,9 @@ NLSET: Final[set[str]] # Added in Python 3.8.20, 3.9.20, 3.10.15, 3.11.10, 3.12.5 SPECIALSNL: Final[set[str]] +if sys.version_info >= (3, 12): + def make_quoted_pairs(value: Any) -> str: ... + def quote_string(value: Any) -> str: ... rfc2047_matcher: Pattern[str] diff --git a/mypy/typeshed/stdlib/enum.pyi b/mypy/typeshed/stdlib/enum.pyi index 3b6c325522d7..4a6287a712af 100644 --- a/mypy/typeshed/stdlib/enum.pyi +++ b/mypy/typeshed/stdlib/enum.pyi @@ -64,7 +64,11 @@ if sys.version_info >= (3, 11): def __init__(self, value: _EnumMemberT) -> None: ... class _EnumDict(dict[str, Any]): - def __init__(self) -> None: ... + if sys.version_info >= (3, 13): + def __init__(self, cls_name: str | None = None) -> None: ... + else: + def __init__(self) -> None: ... + def __setitem__(self, key: str, value: Any) -> None: ... if sys.version_info >= (3, 11): # See comment above `typing.MutableMapping.update` diff --git a/mypy/typeshed/stdlib/http/server.pyi b/mypy/typeshed/stdlib/http/server.pyi index 07cde553c1df..b273e19c10cd 100644 --- a/mypy/typeshed/stdlib/http/server.pyi +++ b/mypy/typeshed/stdlib/http/server.pyi @@ -61,7 +61,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): client_address: _socket._RetAddress, server: socketserver.BaseServer, *, - directory: str | None = None, + directory: StrPath | None = None, ) -> None: ... def do_GET(self) -> None: ... def do_HEAD(self) -> None: ... diff --git a/mypy/typeshed/stdlib/importlib/resources/_common.pyi b/mypy/typeshed/stdlib/importlib/resources/_common.pyi index f04f70f25e23..f1056f62ed6e 100644 --- a/mypy/typeshed/stdlib/importlib/resources/_common.pyi +++ b/mypy/typeshed/stdlib/importlib/resources/_common.pyi @@ -16,7 +16,7 @@ if sys.version_info >= (3, 11): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable] + func: Callable[[Anchor | None], Traversable], ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi index c6836c837eaa..43b3dd529887 100644 --- a/mypy/typeshed/stdlib/inspect.pyi +++ b/mypy/typeshed/stdlib/inspect.pyi @@ -370,7 +370,7 @@ if sys.version_info >= (3, 12): AGEN_CLOSED: Final = "AGEN_CLOSED" def getasyncgenstate( - agen: AsyncGenerator[Any, Any] + agen: AsyncGenerator[Any, Any], ) -> Literal["AGEN_CREATED", "AGEN_RUNNING", "AGEN_SUSPENDED", "AGEN_CLOSED"]: ... def getasyncgenlocals(agen: AsyncGeneratorType[Any, Any]) -> dict[str, Any]: ... @@ -590,7 +590,7 @@ GEN_SUSPENDED: Final = "GEN_SUSPENDED" GEN_CLOSED: Final = "GEN_CLOSED" def getgeneratorstate( - generator: Generator[Any, Any, Any] + generator: Generator[Any, Any, Any], ) -> Literal["GEN_CREATED", "GEN_RUNNING", "GEN_SUSPENDED", "GEN_CLOSED"]: ... CORO_CREATED: Final = "CORO_CREATED" @@ -599,7 +599,7 @@ CORO_SUSPENDED: Final = "CORO_SUSPENDED" CORO_CLOSED: Final = "CORO_CLOSED" def getcoroutinestate( - coroutine: Coroutine[Any, Any, Any] + coroutine: Coroutine[Any, Any, Any], ) -> Literal["CORO_CREATED", "CORO_RUNNING", "CORO_SUSPENDED", "CORO_CLOSED"]: ... def getgeneratorlocals(generator: Generator[Any, Any, Any]) -> dict[str, Any]: ... def getcoroutinelocals(coroutine: Coroutine[Any, Any, Any]) -> dict[str, Any]: ... diff --git a/mypy/typeshed/stdlib/ipaddress.pyi b/mypy/typeshed/stdlib/ipaddress.pyi index 0563ed9b00ba..e8e81abc6f79 100644 --- a/mypy/typeshed/stdlib/ipaddress.pyi +++ b/mypy/typeshed/stdlib/ipaddress.pyi @@ -18,7 +18,7 @@ def ip_network( address: _RawIPAddress | _RawNetworkPart | tuple[_RawIPAddress] | tuple[_RawIPAddress, int], strict: bool = True ) -> IPv4Network | IPv6Network: ... def ip_interface( - address: _RawIPAddress | _RawNetworkPart | tuple[_RawIPAddress] | tuple[_RawIPAddress, int] + address: _RawIPAddress | _RawNetworkPart | tuple[_RawIPAddress] | tuple[_RawIPAddress, int], ) -> IPv4Interface | IPv6Interface: ... class _IPAddressBase: diff --git a/mypy/typeshed/stdlib/json/encoder.pyi b/mypy/typeshed/stdlib/json/encoder.pyi index aa4a3bdf61d4..83b78666d4a7 100644 --- a/mypy/typeshed/stdlib/json/encoder.pyi +++ b/mypy/typeshed/stdlib/json/encoder.pyi @@ -2,11 +2,11 @@ from collections.abc import Callable, Iterator from re import Pattern from typing import Any, Final -ESCAPE: Final[Pattern[str]] -ESCAPE_ASCII: Final[Pattern[str]] -HAS_UTF8: Final[Pattern[bytes]] -ESCAPE_DCT: Final[dict[str, str]] -INFINITY: Final[float] +ESCAPE: Final[Pattern[str]] # undocumented +ESCAPE_ASCII: Final[Pattern[str]] # undocumented +HAS_UTF8: Final[Pattern[bytes]] # undocumented +ESCAPE_DCT: Final[dict[str, str]] # undocumented +INFINITY: Final[float] # undocumented def py_encode_basestring(s: str) -> str: ... # undocumented def py_encode_basestring_ascii(s: str) -> str: ... # undocumented diff --git a/mypy/typeshed/stdlib/json/scanner.pyi b/mypy/typeshed/stdlib/json/scanner.pyi index f3b98996b752..68b42e92d295 100644 --- a/mypy/typeshed/stdlib/json/scanner.pyi +++ b/mypy/typeshed/stdlib/json/scanner.pyi @@ -1,3 +1,7 @@ from _json import make_scanner as make_scanner +from re import Pattern +from typing import Final __all__ = ["make_scanner"] + +NUMBER_RE: Final[Pattern[str]] # undocumented diff --git a/mypy/typeshed/stdlib/math.pyi b/mypy/typeshed/stdlib/math.pyi index 2bb61e0669b4..86f71f27580a 100644 --- a/mypy/typeshed/stdlib/math.pyi +++ b/mypy/typeshed/stdlib/math.pyi @@ -1,6 +1,6 @@ import sys from collections.abc import Iterable -from typing import Protocol, SupportsFloat, SupportsIndex, TypeVar, overload +from typing import Final, Protocol, SupportsFloat, SupportsIndex, TypeVar, overload from typing_extensions import TypeAlias _T = TypeVar("_T") @@ -8,11 +8,11 @@ _T_co = TypeVar("_T_co", covariant=True) _SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex -e: float -pi: float -inf: float -nan: float -tau: float +e: Final[float] +pi: Final[float] +inf: Final[float] +nan: Final[float] +tau: Final[float] def acos(x: _SupportsFloatOrIndex, /) -> float: ... def acosh(x: _SupportsFloatOrIndex, /) -> float: ... diff --git a/mypy/typeshed/stdlib/optparse.pyi b/mypy/typeshed/stdlib/optparse.pyi index ff5e83cf26db..56a4574bdba8 100644 --- a/mypy/typeshed/stdlib/optparse.pyi +++ b/mypy/typeshed/stdlib/optparse.pyi @@ -1,8 +1,8 @@ import builtins -from _typeshed import Incomplete, MaybeNone +from _typeshed import MaybeNone, SupportsWrite from abc import abstractmethod from collections.abc import Callable, Iterable, Mapping, Sequence -from typing import IO, Any, AnyStr, ClassVar, Literal, NoReturn, overload +from typing import Any, ClassVar, Final, Literal, NoReturn, overload from typing_extensions import Self __all__ = [ @@ -24,10 +24,10 @@ __all__ = [ "BadOptionError", "check_choice", ] - -NO_DEFAULT: tuple[str, ...] -SUPPRESS_HELP: str -SUPPRESS_USAGE: str +# pytype is not happy with `NO_DEFAULT: Final = ("NO", "DEFAULT")` +NO_DEFAULT: Final[tuple[Literal["NO"], Literal["DEFAULT"]]] +SUPPRESS_HELP: Final = "SUPPRESSHELP" +SUPPRESS_USAGE: Final = "SUPPRESSUSAGE" # Can return complex, float, or int depending on the option's type def check_builtin(option: Option, opt: str, value: str) -> complex: ... @@ -274,13 +274,13 @@ class OptionParser(OptionContainer): def _add_version_option(self) -> None: ... def _create_option_list(self) -> None: ... def _get_all_options(self) -> list[Option]: ... - def _get_args(self, args: Iterable[Incomplete]) -> list[Incomplete]: ... + def _get_args(self, args: list[str] | None) -> list[str]: ... def _init_parsing_state(self) -> None: ... def _match_long_opt(self, opt: str) -> str: ... - def _populate_option_list(self, option_list: Iterable[Option], add_help: bool = True) -> None: ... - def _process_args(self, largs: list[Incomplete], rargs: list[Incomplete], values: Values) -> None: ... - def _process_long_opt(self, rargs: list[Incomplete], values) -> None: ... - def _process_short_opts(self, rargs: list[Incomplete], values) -> None: ... + def _populate_option_list(self, option_list: Iterable[Option] | None, add_help: bool = True) -> None: ... + def _process_args(self, largs: list[str], rargs: list[str], values: Values) -> None: ... + def _process_long_opt(self, rargs: list[str], values: Values) -> None: ... + def _process_short_opts(self, rargs: list[str], values: Values) -> None: ... @overload def add_option_group(self, opt_group: OptionGroup, /) -> OptionGroup: ... @overload @@ -299,14 +299,11 @@ class OptionParser(OptionContainer): def get_prog_name(self) -> str: ... def get_usage(self) -> str: ... def get_version(self) -> str: ... - @overload - def parse_args(self, args: None = None, values: Values | None = None) -> tuple[Values, list[str]]: ... - @overload - def parse_args(self, args: Sequence[AnyStr], values: Values | None = None) -> tuple[Values, list[AnyStr]]: ... - def print_usage(self, file: IO[str] | None = None) -> None: ... - def print_help(self, file: IO[str] | None = None) -> None: ... - def print_version(self, file: IO[str] | None = None) -> None: ... - def set_default(self, dest, value) -> None: ... - def set_defaults(self, **kwargs) -> None: ... - def set_process_default_values(self, process) -> None: ... - def set_usage(self, usage: str) -> None: ... + def parse_args(self, args: list[str] | None = None, values: Values | None = None) -> tuple[Values, list[str]]: ... + def print_usage(self, file: SupportsWrite[str] | None = None) -> None: ... + def print_help(self, file: SupportsWrite[str] | None = None) -> None: ... + def print_version(self, file: SupportsWrite[str] | None = None) -> None: ... + def set_default(self, dest: str, value: Any) -> None: ... # default value can be "any" type + def set_defaults(self, **kwargs: Any) -> None: ... # default values can be "any" type + def set_process_default_values(self, process: bool) -> None: ... + def set_usage(self, usage: str | None) -> None: ... diff --git a/mypy/typeshed/stdlib/os/__init__.pyi b/mypy/typeshed/stdlib/os/__init__.pyi index 64691b514a48..4a7c03632a67 100644 --- a/mypy/typeshed/stdlib/os/__init__.pyi +++ b/mypy/typeshed/stdlib/os/__init__.pyi @@ -240,6 +240,7 @@ if sys.platform == "linux" and sys.version_info >= (3, 12): "CLONE_VM", "setns", "unshare", + "PIDFD_NONBLOCK", ] if sys.platform == "linux" and sys.version_info >= (3, 10): __all__ += [ @@ -1603,6 +1604,9 @@ if sys.version_info >= (3, 9): if sys.platform == "linux": def pidfd_open(pid: int, flags: int = ...) -> int: ... +if sys.version_info >= (3, 12) and sys.platform == "linux": + PIDFD_NONBLOCK: Final = 2048 + if sys.version_info >= (3, 12) and sys.platform == "win32": def listdrives() -> list[str]: ... def listmounts(volume: str) -> list[str]: ... diff --git a/mypy/typeshed/stdlib/posix.pyi b/mypy/typeshed/stdlib/posix.pyi index 7a4d6cb4bdbe..e7223842ace5 100644 --- a/mypy/typeshed/stdlib/posix.pyi +++ b/mypy/typeshed/stdlib/posix.pyi @@ -379,6 +379,7 @@ if sys.platform != "win32": CLONE_SYSVSEM as CLONE_SYSVSEM, CLONE_THREAD as CLONE_THREAD, CLONE_VM as CLONE_VM, + PIDFD_NONBLOCK as PIDFD_NONBLOCK, setns as setns, unshare as unshare, ) diff --git a/mypy/typeshed/stdlib/re.pyi b/mypy/typeshed/stdlib/re.pyi index b8fe2e9e1a46..fccdedae9436 100644 --- a/mypy/typeshed/stdlib/re.pyi +++ b/mypy/typeshed/stdlib/re.pyi @@ -4,7 +4,7 @@ import sre_constants import sys from _typeshed import MaybeNone, ReadableBuffer from collections.abc import Callable, Iterator, Mapping -from typing import Any, AnyStr, Generic, Literal, TypeVar, final, overload +from typing import Any, AnyStr, Final, Generic, Literal, TypeVar, final, overload from typing_extensions import TypeAlias if sys.version_info >= (3, 9): @@ -224,25 +224,27 @@ class RegexFlag(enum.IntFlag): if sys.version_info >= (3, 11): NOFLAG = 0 -A = RegexFlag.A -ASCII = RegexFlag.ASCII -DEBUG = RegexFlag.DEBUG -I = RegexFlag.I -IGNORECASE = RegexFlag.IGNORECASE -L = RegexFlag.L -LOCALE = RegexFlag.LOCALE -M = RegexFlag.M -MULTILINE = RegexFlag.MULTILINE -S = RegexFlag.S -DOTALL = RegexFlag.DOTALL -X = RegexFlag.X -VERBOSE = RegexFlag.VERBOSE -U = RegexFlag.U -UNICODE = RegexFlag.UNICODE +A: Final = RegexFlag.A +ASCII: Final = RegexFlag.ASCII +DEBUG: Final = RegexFlag.DEBUG +I: Final = RegexFlag.I +IGNORECASE: Final = RegexFlag.IGNORECASE +L: Final = RegexFlag.L +LOCALE: Final = RegexFlag.LOCALE +M: Final = RegexFlag.M +MULTILINE: Final = RegexFlag.MULTILINE +S: Final = RegexFlag.S +DOTALL: Final = RegexFlag.DOTALL +X: Final = RegexFlag.X +VERBOSE: Final = RegexFlag.VERBOSE +U: Final = RegexFlag.U +UNICODE: Final = RegexFlag.UNICODE if sys.version_info < (3, 13): - T = RegexFlag.T - TEMPLATE = RegexFlag.TEMPLATE + T: Final = RegexFlag.T + TEMPLATE: Final = RegexFlag.TEMPLATE if sys.version_info >= (3, 11): + # pytype chokes on `NOFLAG: Final = RegexFlag.NOFLAG` with `LiteralValueError` + # mypy chokes on `NOFLAG: Final[Literal[RegexFlag.NOFLAG]]` with `Literal[...] is invalid` NOFLAG = RegexFlag.NOFLAG _FlagsType: TypeAlias = int | RegexFlag diff --git a/mypy/typeshed/stdlib/shutil.pyi b/mypy/typeshed/stdlib/shutil.pyi index dcff18d110bd..4a19a96a306c 100644 --- a/mypy/typeshed/stdlib/shutil.pyi +++ b/mypy/typeshed/stdlib/shutil.pyi @@ -83,7 +83,7 @@ class _RmtreeType(Protocol): self, path: StrOrBytesPath, ignore_errors: bool, - onerror: _OnErrorCallback, + onerror: _OnErrorCallback | None, *, onexc: None = None, dir_fd: int | None = None, @@ -95,7 +95,7 @@ class _RmtreeType(Protocol): path: StrOrBytesPath, ignore_errors: bool = False, *, - onerror: _OnErrorCallback, + onerror: _OnErrorCallback | None, onexc: None = None, dir_fd: int | None = None, ) -> None: ... diff --git a/mypy/typeshed/stdlib/socket.pyi b/mypy/typeshed/stdlib/socket.pyi index f982c9b893d8..1c996ac32278 100644 --- a/mypy/typeshed/stdlib/socket.pyi +++ b/mypy/typeshed/stdlib/socket.pyi @@ -515,7 +515,7 @@ if sys.platform != "win32": "IPV6_RTHDRDSTOPTS", ] - if sys.platform != "darwin" or sys.version_info >= (3, 13): + if sys.platform != "darwin": from _socket import SO_BINDTODEVICE as SO_BINDTODEVICE __all__ += ["SO_BINDTODEVICE"] diff --git a/mypy/typeshed/stdlib/sre_constants.pyi b/mypy/typeshed/stdlib/sre_constants.pyi index 383f0f7eb8bd..c41a52b26d5a 100644 --- a/mypy/typeshed/stdlib/sre_constants.pyi +++ b/mypy/typeshed/stdlib/sre_constants.pyi @@ -1,17 +1,17 @@ import sys from re import error as error -from typing import Any +from typing import Final from typing_extensions import Self -MAXGROUPS: int +MAXGROUPS: Final[int] -MAGIC: int +MAGIC: Final[int] class _NamedIntConstant(int): - name: Any + name: str def __new__(cls, value: int, name: str) -> Self: ... -MAXREPEAT: _NamedIntConstant +MAXREPEAT: Final[_NamedIntConstant] OPCODES: list[_NamedIntConstant] ATCODES: list[_NamedIntConstant] CHCODES: list[_NamedIntConstant] @@ -23,102 +23,104 @@ AT_LOCALE: dict[_NamedIntConstant, _NamedIntConstant] AT_UNICODE: dict[_NamedIntConstant, _NamedIntConstant] CH_LOCALE: dict[_NamedIntConstant, _NamedIntConstant] CH_UNICODE: dict[_NamedIntConstant, _NamedIntConstant] +# flags if sys.version_info < (3, 13): - SRE_FLAG_TEMPLATE: int -SRE_FLAG_IGNORECASE: int -SRE_FLAG_LOCALE: int -SRE_FLAG_MULTILINE: int -SRE_FLAG_DOTALL: int -SRE_FLAG_UNICODE: int -SRE_FLAG_VERBOSE: int -SRE_FLAG_DEBUG: int -SRE_FLAG_ASCII: int -SRE_INFO_PREFIX: int -SRE_INFO_LITERAL: int -SRE_INFO_CHARSET: int + SRE_FLAG_TEMPLATE: Final = 1 +SRE_FLAG_IGNORECASE: Final = 2 +SRE_FLAG_LOCALE: Final = 4 +SRE_FLAG_MULTILINE: Final = 8 +SRE_FLAG_DOTALL: Final = 16 +SRE_FLAG_UNICODE: Final = 32 +SRE_FLAG_VERBOSE: Final = 64 +SRE_FLAG_DEBUG: Final = 128 +SRE_FLAG_ASCII: Final = 256 +# flags for INFO primitive +SRE_INFO_PREFIX: Final = 1 +SRE_INFO_LITERAL: Final = 2 +SRE_INFO_CHARSET: Final = 4 # Stubgen above; manually defined constants below (dynamic at runtime) # from OPCODES -FAILURE: _NamedIntConstant -SUCCESS: _NamedIntConstant -ANY: _NamedIntConstant -ANY_ALL: _NamedIntConstant -ASSERT: _NamedIntConstant -ASSERT_NOT: _NamedIntConstant -AT: _NamedIntConstant -BRANCH: _NamedIntConstant +FAILURE: Final[_NamedIntConstant] +SUCCESS: Final[_NamedIntConstant] +ANY: Final[_NamedIntConstant] +ANY_ALL: Final[_NamedIntConstant] +ASSERT: Final[_NamedIntConstant] +ASSERT_NOT: Final[_NamedIntConstant] +AT: Final[_NamedIntConstant] +BRANCH: Final[_NamedIntConstant] if sys.version_info < (3, 11): - CALL: _NamedIntConstant -CATEGORY: _NamedIntConstant -CHARSET: _NamedIntConstant -BIGCHARSET: _NamedIntConstant -GROUPREF: _NamedIntConstant -GROUPREF_EXISTS: _NamedIntConstant -GROUPREF_IGNORE: _NamedIntConstant -IN: _NamedIntConstant -IN_IGNORE: _NamedIntConstant -INFO: _NamedIntConstant -JUMP: _NamedIntConstant -LITERAL: _NamedIntConstant -LITERAL_IGNORE: _NamedIntConstant -MARK: _NamedIntConstant -MAX_UNTIL: _NamedIntConstant -MIN_UNTIL: _NamedIntConstant -NOT_LITERAL: _NamedIntConstant -NOT_LITERAL_IGNORE: _NamedIntConstant -NEGATE: _NamedIntConstant -RANGE: _NamedIntConstant -REPEAT: _NamedIntConstant -REPEAT_ONE: _NamedIntConstant -SUBPATTERN: _NamedIntConstant -MIN_REPEAT_ONE: _NamedIntConstant + CALL: Final[_NamedIntConstant] +CATEGORY: Final[_NamedIntConstant] +CHARSET: Final[_NamedIntConstant] +BIGCHARSET: Final[_NamedIntConstant] +GROUPREF: Final[_NamedIntConstant] +GROUPREF_EXISTS: Final[_NamedIntConstant] +GROUPREF_IGNORE: Final[_NamedIntConstant] +IN: Final[_NamedIntConstant] +IN_IGNORE: Final[_NamedIntConstant] +INFO: Final[_NamedIntConstant] +JUMP: Final[_NamedIntConstant] +LITERAL: Final[_NamedIntConstant] +LITERAL_IGNORE: Final[_NamedIntConstant] +MARK: Final[_NamedIntConstant] +MAX_UNTIL: Final[_NamedIntConstant] +MIN_UNTIL: Final[_NamedIntConstant] +NOT_LITERAL: Final[_NamedIntConstant] +NOT_LITERAL_IGNORE: Final[_NamedIntConstant] +NEGATE: Final[_NamedIntConstant] +RANGE: Final[_NamedIntConstant] +REPEAT: Final[_NamedIntConstant] +REPEAT_ONE: Final[_NamedIntConstant] +SUBPATTERN: Final[_NamedIntConstant] +MIN_REPEAT_ONE: Final[_NamedIntConstant] if sys.version_info >= (3, 11): - ATOMIC_GROUP: _NamedIntConstant - POSSESSIVE_REPEAT: _NamedIntConstant - POSSESSIVE_REPEAT_ONE: _NamedIntConstant -RANGE_UNI_IGNORE: _NamedIntConstant -GROUPREF_LOC_IGNORE: _NamedIntConstant -GROUPREF_UNI_IGNORE: _NamedIntConstant -IN_LOC_IGNORE: _NamedIntConstant -IN_UNI_IGNORE: _NamedIntConstant -LITERAL_LOC_IGNORE: _NamedIntConstant -LITERAL_UNI_IGNORE: _NamedIntConstant -NOT_LITERAL_LOC_IGNORE: _NamedIntConstant -NOT_LITERAL_UNI_IGNORE: _NamedIntConstant -MIN_REPEAT: _NamedIntConstant -MAX_REPEAT: _NamedIntConstant + ATOMIC_GROUP: Final[_NamedIntConstant] + POSSESSIVE_REPEAT: Final[_NamedIntConstant] + POSSESSIVE_REPEAT_ONE: Final[_NamedIntConstant] +RANGE_UNI_IGNORE: Final[_NamedIntConstant] +GROUPREF_LOC_IGNORE: Final[_NamedIntConstant] +GROUPREF_UNI_IGNORE: Final[_NamedIntConstant] +IN_LOC_IGNORE: Final[_NamedIntConstant] +IN_UNI_IGNORE: Final[_NamedIntConstant] +LITERAL_LOC_IGNORE: Final[_NamedIntConstant] +LITERAL_UNI_IGNORE: Final[_NamedIntConstant] +NOT_LITERAL_LOC_IGNORE: Final[_NamedIntConstant] +NOT_LITERAL_UNI_IGNORE: Final[_NamedIntConstant] +MIN_REPEAT: Final[_NamedIntConstant] +MAX_REPEAT: Final[_NamedIntConstant] # from ATCODES -AT_BEGINNING: _NamedIntConstant -AT_BEGINNING_LINE: _NamedIntConstant -AT_BEGINNING_STRING: _NamedIntConstant -AT_BOUNDARY: _NamedIntConstant -AT_NON_BOUNDARY: _NamedIntConstant -AT_END: _NamedIntConstant -AT_END_LINE: _NamedIntConstant -AT_END_STRING: _NamedIntConstant -AT_LOC_BOUNDARY: _NamedIntConstant -AT_LOC_NON_BOUNDARY: _NamedIntConstant -AT_UNI_BOUNDARY: _NamedIntConstant -AT_UNI_NON_BOUNDARY: _NamedIntConstant +AT_BEGINNING: Final[_NamedIntConstant] +AT_BEGINNING_LINE: Final[_NamedIntConstant] +AT_BEGINNING_STRING: Final[_NamedIntConstant] +AT_BOUNDARY: Final[_NamedIntConstant] +AT_NON_BOUNDARY: Final[_NamedIntConstant] +AT_END: Final[_NamedIntConstant] +AT_END_LINE: Final[_NamedIntConstant] +AT_END_STRING: Final[_NamedIntConstant] +AT_LOC_BOUNDARY: Final[_NamedIntConstant] +AT_LOC_NON_BOUNDARY: Final[_NamedIntConstant] +AT_UNI_BOUNDARY: Final[_NamedIntConstant] +AT_UNI_NON_BOUNDARY: Final[_NamedIntConstant] # from CHCODES -CATEGORY_DIGIT: _NamedIntConstant -CATEGORY_NOT_DIGIT: _NamedIntConstant -CATEGORY_SPACE: _NamedIntConstant -CATEGORY_NOT_SPACE: _NamedIntConstant -CATEGORY_WORD: _NamedIntConstant -CATEGORY_NOT_WORD: _NamedIntConstant -CATEGORY_LINEBREAK: _NamedIntConstant -CATEGORY_NOT_LINEBREAK: _NamedIntConstant -CATEGORY_LOC_WORD: _NamedIntConstant -CATEGORY_LOC_NOT_WORD: _NamedIntConstant -CATEGORY_UNI_DIGIT: _NamedIntConstant -CATEGORY_UNI_NOT_DIGIT: _NamedIntConstant -CATEGORY_UNI_SPACE: _NamedIntConstant -CATEGORY_UNI_NOT_SPACE: _NamedIntConstant -CATEGORY_UNI_WORD: _NamedIntConstant -CATEGORY_UNI_NOT_WORD: _NamedIntConstant -CATEGORY_UNI_LINEBREAK: _NamedIntConstant -CATEGORY_UNI_NOT_LINEBREAK: _NamedIntConstant +CATEGORY_DIGIT: Final[_NamedIntConstant] +CATEGORY_NOT_DIGIT: Final[_NamedIntConstant] +CATEGORY_SPACE: Final[_NamedIntConstant] +CATEGORY_NOT_SPACE: Final[_NamedIntConstant] +CATEGORY_WORD: Final[_NamedIntConstant] +CATEGORY_NOT_WORD: Final[_NamedIntConstant] +CATEGORY_LINEBREAK: Final[_NamedIntConstant] +CATEGORY_NOT_LINEBREAK: Final[_NamedIntConstant] +CATEGORY_LOC_WORD: Final[_NamedIntConstant] +CATEGORY_LOC_NOT_WORD: Final[_NamedIntConstant] +CATEGORY_UNI_DIGIT: Final[_NamedIntConstant] +CATEGORY_UNI_NOT_DIGIT: Final[_NamedIntConstant] +CATEGORY_UNI_SPACE: Final[_NamedIntConstant] +CATEGORY_UNI_NOT_SPACE: Final[_NamedIntConstant] +CATEGORY_UNI_WORD: Final[_NamedIntConstant] +CATEGORY_UNI_NOT_WORD: Final[_NamedIntConstant] +CATEGORY_UNI_LINEBREAK: Final[_NamedIntConstant] +CATEGORY_UNI_NOT_LINEBREAK: Final[_NamedIntConstant] diff --git a/mypy/typeshed/stdlib/sys/__init__.pyi b/mypy/typeshed/stdlib/sys/__init__.pyi index d11e64d109b5..4aa1699e8b42 100644 --- a/mypy/typeshed/stdlib/sys/__init__.pyi +++ b/mypy/typeshed/stdlib/sys/__init__.pyi @@ -396,6 +396,7 @@ def intern(string: str, /) -> str: ... if sys.version_info >= (3, 13): def _is_gil_enabled() -> bool: ... + def _clear_internal_caches() -> None: ... def is_finalizing() -> bool: ... def breakpointhook(*args: Any, **kwargs: Any) -> Any: ... diff --git a/mypy/typeshed/stdlib/tkinter/ttk.pyi b/mypy/typeshed/stdlib/tkinter/ttk.pyi index dacef0620b22..5328e461ebdc 100644 --- a/mypy/typeshed/stdlib/tkinter/ttk.pyi +++ b/mypy/typeshed/stdlib/tkinter/ttk.pyi @@ -1100,7 +1100,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView): open: bool = ..., tags: str | list[str] | tuple[str, ...] = ..., ) -> None: ... - def move(self, item: str | int, parent: str, index: int) -> None: ... + def move(self, item: str | int, parent: str, index: int | Literal["end"]) -> None: ... reattach = move def next(self, item: str | int) -> str: ... # returning empty string means last item def parent(self, item: str | int) -> str: ... diff --git a/mypy/typeshed/stdlib/tokenize.pyi b/mypy/typeshed/stdlib/tokenize.pyi index 7b68f791a8c0..a1c4b412da83 100644 --- a/mypy/typeshed/stdlib/tokenize.pyi +++ b/mypy/typeshed/stdlib/tokenize.pyi @@ -125,14 +125,16 @@ class Untokenizer: prev_col: int encoding: str | None def add_whitespace(self, start: _Position) -> None: ... + if sys.version_info >= (3, 13): + def add_backslash_continuation(self, start: _Position) -> None: ... + def untokenize(self, iterable: Iterable[_Token]) -> str: ... def compat(self, token: Sequence[int | str], iterable: Iterable[_Token]) -> None: ... if sys.version_info >= (3, 12): def escape_brackets(self, token: str) -> str: ... -# the docstring says "returns bytes" but is incorrect -- -# if the ENCODING token is missing, it skips the encode -def untokenize(iterable: Iterable[_Token]) -> Any: ... +# Returns str, unless the ENCODING token is present, in which case it returns bytes. +def untokenize(iterable: Iterable[_Token]) -> str | Any: ... def detect_encoding(readline: Callable[[], bytes | bytearray]) -> tuple[str, Sequence[bytes]]: ... def tokenize(readline: Callable[[], bytes | bytearray]) -> Generator[TokenInfo, None, None]: ... def generate_tokens(readline: Callable[[], str]) -> Generator[TokenInfo, None, None]: ... diff --git a/mypy/typeshed/stdlib/types.pyi b/mypy/typeshed/stdlib/types.pyi index b294a0b2f8f7..d41ca0d1c367 100644 --- a/mypy/typeshed/stdlib/types.pyi +++ b/mypy/typeshed/stdlib/types.pyi @@ -640,6 +640,7 @@ if sys.version_info >= (3, 9): def __getitem__(self, typeargs: Any, /) -> GenericAlias: ... def __eq__(self, value: object, /) -> bool: ... def __hash__(self) -> int: ... + def __mro_entries__(self, bases: Iterable[object], /) -> tuple[type, ...]: ... if sys.version_info >= (3, 11): @property def __unpacked__(self) -> bool: ...