Skip to content

Sync typeshed #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/mypy_primer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
# Only run on PR, since we diff against master
pull_request:
paths-ignore:
- '**'
- 'docs/**'
- '**/*.rst'
- '**/*.md'
Expand Down
101 changes: 51 additions & 50 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ on:
permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
# concurrency:
# group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
# cancel-in-progress: true

jobs:
main:
Expand All @@ -31,40 +31,40 @@ jobs:
include:
# Make sure to run mypyc compiled unit tests for both
# the oldest and newest supported Python versions
- name: Test suite with py39-ubuntu, mypyc-compiled
python: '3.9'
os: ubuntu-22.04-arm
toxenv: py
tox_extra_args: "-n 4"
test_mypyc: true
- name: Test suite with py39-windows-64
python: '3.9'
os: windows-latest
toxenv: py39
tox_extra_args: "-n 4"
- name: Test suite with py310-ubuntu
python: '3.10'
os: ubuntu-22.04-arm
toxenv: py
tox_extra_args: "-n 4"
- name: Test suite with py311-ubuntu, mypyc-compiled
python: '3.11'
os: ubuntu-22.04-arm
toxenv: py
tox_extra_args: "-n 4"
test_mypyc: true
# - name: Test suite with py39-ubuntu, mypyc-compiled
# python: '3.9'
# os: ubuntu-22.04-arm
# toxenv: py
# tox_extra_args: "-n 4"
# test_mypyc: true
# - name: Test suite with py39-windows-64
# python: '3.9'
# os: windows-latest
# toxenv: py39
# tox_extra_args: "-n 4"
# - name: Test suite with py310-ubuntu
# python: '3.10'
# os: ubuntu-22.04-arm
# toxenv: py
# tox_extra_args: "-n 4"
# - name: Test suite with py311-ubuntu, mypyc-compiled
# python: '3.11'
# os: ubuntu-22.04-arm
# toxenv: py
# tox_extra_args: "-n 4"
# test_mypyc: true
- name: Test suite with py312-ubuntu, mypyc-compiled
python: '3.12'
os: ubuntu-22.04-arm
toxenv: py
tox_extra_args: "-n 4"
test_mypyc: true
- name: Test suite with py313-ubuntu, mypyc-compiled
python: '3.13'
os: ubuntu-22.04-arm
toxenv: py
tox_extra_args: "-n 4"
tox_extra_args: "-n0 -k testDeprecatedRemoveFunctionDeprecationIndirectImport"
test_mypyc: true
# - name: Test suite with py313-ubuntu, mypyc-compiled
# python: '3.13'
# os: ubuntu-22.04-arm
# toxenv: py
# tox_extra_args: "-n 4"
# test_mypyc: true

# - name: Test suite with py314-dev-ubuntu
# python: '3.14-dev'
Expand All @@ -74,12 +74,12 @@ jobs:
# allow_failure: true
# test_mypyc: true

- name: mypyc runtime tests with py39-macos
python: '3.9.21'
# TODO: macos-13 is the last one to support Python 3.9, change it to macos-latest when updating the Python version
os: macos-13
toxenv: py
tox_extra_args: "-n 3 mypyc/test/test_run.py mypyc/test/test_external.py"
# - name: mypyc runtime tests with py39-macos
# python: '3.9.21'
# # TODO: macos-13 is the last one to support Python 3.9, change it to macos-latest when updating the Python version
# os: macos-13
# toxenv: py
# tox_extra_args: "-n 3 mypyc/test/test_run.py mypyc/test/test_external.py"
# This is broken. See
# - https://github.com/python/mypy/issues/17819
# - https://github.com/python/mypy/pull/17822
Expand All @@ -90,22 +90,22 @@ jobs:
# tox_extra_args: "-n 4 mypyc/test/test_run.py mypyc/test/test_external.py"
# debug_build: true

- name: Type check our own code (py39-ubuntu)
python: '3.9'
os: ubuntu-latest
toxenv: type
- name: Type check our own code (py39-windows-64)
python: '3.9'
os: windows-latest
toxenv: type
# - name: Type check our own code (py39-ubuntu)
# python: '3.9'
# os: ubuntu-latest
# toxenv: type
# - name: Type check our own code (py39-windows-64)
# python: '3.9'
# os: windows-latest
# toxenv: type

# We also run these checks with pre-commit in CI,
# but it's useful to run them with tox too,
# to ensure the tox env works as expected
- name: Formatting and code style with Black + ruff
python: '3.10'
os: ubuntu-latest
toxenv: lint
# - name: Formatting and code style with Black + ruff
# python: '3.10'
# os: ubuntu-latest
# toxenv: lint

name: ${{ matrix.name }}
timeout-minutes: 60
Expand Down Expand Up @@ -190,6 +190,7 @@ jobs:
runs-on: ubuntu-latest
name: Test mypyc suite with 32-bit Python
timeout-minutes: 60
if: false
env:
TOX_SKIP_MISSING_INTERPRETERS: False
# Rich (pip)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
From b5f2cc9633f9f6cd9326eee96a32efb3aff70701 Mon Sep 17 00:00:00 2001
From: Marc Mueller <[email protected]>
Date: Sat, 15 Feb 2025 20:11:06 +0100
Subject: [PATCH] Partially revert Clean up argparse hacks

---
mypy/typeshed/stdlib/argparse.pyi | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi
index 029bfeefe..9dbd8c308 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, NoReturn, Protocol, TypeVar, overload
+from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload
from typing_extensions import Self, TypeAlias, deprecated

__all__ = [
@@ -38,7 +38,9 @@ ONE_OR_MORE: Final = "+"
OPTIONAL: Final = "?"
PARSER: Final = "A..."
REMAINDER: Final = "..."
-SUPPRESS: Final = "==SUPPRESS=="
+_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
ZERO_OR_MORE: Final = "*"
_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented

@@ -81,7 +83,7 @@ class _ActionsContainer:
# 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,
+ nargs: int | str | _SUPPRESS_T | None = None,
const: Any = ...,
default: Any = ...,
type: _ActionType = ...,
--
2.48.1

16 changes: 8 additions & 8 deletions mypy/typeshed/stdlib/_decimal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/_socket.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
20 changes: 8 additions & 12 deletions mypy/typeshed/stdlib/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ _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 = "?"
Expand All @@ -51,7 +42,7 @@ _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
ZERO_OR_MORE: Final = "*"
_UNRECOGNIZED_ARGS_ATTR: Final[str] # undocumented
_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented

class ArgumentError(Exception):
argument_name: str | None
Expand Down Expand Up @@ -86,8 +77,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 | _SUPPRESS_T | None = None,
const: Any = ...,
default: Any = ...,
type: _ActionType = ...,
Expand Down
4 changes: 3 additions & 1 deletion mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]: ...
Expand Down
9 changes: 7 additions & 2 deletions mypy/typeshed/stdlib/bdb.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions mypy/typeshed/stdlib/cmath.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down
22 changes: 11 additions & 11 deletions mypy/typeshed/stdlib/decimal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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
Expand All @@ -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: ...
Expand Down
Loading