Skip to content

Commit

Permalink
Bump mypy to 1.11.1 (python#12463)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored and max-muoto committed Aug 17, 2024
1 parent 8f08609 commit 60f2ae3
Show file tree
Hide file tree
Showing 46 changed files with 120 additions and 113 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ jobs:
check-latest: true
- name: Install dependencies
run: pip install -r requirements-tests.txt
- name: Install mypy from git
run: pip install git+https://github.com/python/mypy@e8a26308d5d06925cf769b62f41ef2e4bc546ada
- name: Run stubtest
run: python tests/stubtest_stdlib.py

Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/stubtest_stdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,5 @@ jobs:
check-latest: true
- name: Install dependencies
run: pip install -r requirements-tests.txt
- name: Install mypy from git
run: pip install git+https://github.com/python/mypy@e8a26308d5d06925cf769b62f41ef2e4bc546ada
- name: Run stubtest
run: python tests/stubtest_stdlib.py
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ black==24.4.2 # must match .pre-commit-config.yaml
flake8==7.1.0 # must match .pre-commit-config.yaml
flake8-noqa==1.4.0 # must match .pre-commit-config.yaml
flake8-pyi==24.6.0 # must match .pre-commit-config.yaml
mypy==1.10.1
mypy==1.11.1
pre-commit-hooks==4.6.0 # must match .pre-commit-config.yaml
pyright==1.1.374
pytype==2024.4.11; platform_system != "Windows" and python_version < "3.12"
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@tests/test_cases/check_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

A = enum.Enum("A", "spam eggs bacon")
B = enum.Enum("B", ["spam", "eggs", "bacon"])
C = enum.Enum("Bar", [("spam", 1), ("eggs", 2), ("bacon", 3)])
D = enum.Enum("Bar", {"spam": 1, "eggs": 2})
C = enum.Enum("C", [("spam", 1), ("eggs", 2), ("bacon", 3)])
D = enum.Enum("D", {"spam": 1, "eggs": 2})

assert_type(A, Type[A])
assert_type(B, Type[B])
Expand Down
12 changes: 6 additions & 6 deletions stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ if sys.version_info >= (3, 10):
@overload
def gather(*coros_or_futures: _FutureLike[_T], return_exceptions: Literal[False] = False) -> Future[list[_T]]: ... # type: ignore[overload-overlap]
@overload
def gather(coro_or_future1: _FutureLike[_T1], /, *, return_exceptions: bool) -> Future[tuple[_T1 | BaseException]]: ... # type: ignore[overload-overlap]
def gather(coro_or_future1: _FutureLike[_T1], /, *, return_exceptions: bool) -> Future[tuple[_T1 | BaseException]]: ...
@overload
def gather( # type: ignore[overload-overlap]
def gather(
coro_or_future1: _FutureLike[_T1], coro_or_future2: _FutureLike[_T2], /, *, return_exceptions: bool
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException]]: ...
@overload
def gather( # type: ignore[overload-overlap]
def gather(
coro_or_future1: _FutureLike[_T1],
coro_or_future2: _FutureLike[_T2],
coro_or_future3: _FutureLike[_T3],
Expand All @@ -166,7 +166,7 @@ if sys.version_info >= (3, 10):
return_exceptions: bool,
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ...
@overload
def gather( # type: ignore[overload-overlap]
def gather(
coro_or_future1: _FutureLike[_T1],
coro_or_future2: _FutureLike[_T2],
coro_or_future3: _FutureLike[_T3],
Expand All @@ -176,7 +176,7 @@ if sys.version_info >= (3, 10):
return_exceptions: bool,
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ...
@overload
def gather( # type: ignore[overload-overlap]
def gather(
coro_or_future1: _FutureLike[_T1],
coro_or_future2: _FutureLike[_T2],
coro_or_future3: _FutureLike[_T3],
Expand All @@ -189,7 +189,7 @@ if sys.version_info >= (3, 10):
tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException]
]: ...
@overload
def gather( # type: ignore[overload-overlap]
def gather(
coro_or_future1: _FutureLike[_T1],
coro_or_future2: _FutureLike[_T2],
coro_or_future3: _FutureLike[_T3],
Expand Down
2 changes: 1 addition & 1 deletion stdlib/asyncio/unix_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ if sys.platform != "win32":

class _UnixSelectorEventLoop(BaseSelectorEventLoop):
if sys.version_info >= (3, 13):
async def create_unix_server( # type: ignore[override]
async def create_unix_server(
self,
protocol_factory: _ProtocolFactory,
path: StrPath | None = None,
Expand Down
5 changes: 2 additions & 3 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1744,17 +1744,16 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
# without creating many false-positive errors (see #7578).
# Instead, we special-case the most common examples of this: bool and literal integers.
@overload
def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ... # type: ignore[overload-overlap]
def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ...
@overload
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
@overload
def sum(iterable: Iterable[_AddableT1], /, start: _AddableT2) -> _AddableT1 | _AddableT2: ...

# The argument to `vars()` has to have a `__dict__` attribute, so the second overload can't be annotated with `object`
# (A "SupportsDunderDict" protocol doesn't work)
# Use a type: ignore to make complaints about overlapping overloads go away
@overload
def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... # type: ignore[overload-overlap]
def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
@overload
def vars(object: Any = ..., /) -> dict[str, Any]: ...

Expand Down
4 changes: 2 additions & 2 deletions stdlib/importlib/metadata/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ if sys.version_info >= (3, 10) and sys.version_info < (3, 12):
@property
def names(self) -> set[str]: ...
@overload
def select(self) -> Self: ... # type: ignore[misc]
def select(self) -> Self: ...
@overload
def select(
self,
Expand Down Expand Up @@ -277,7 +277,7 @@ if sys.version_info >= (3, 12):

elif sys.version_info >= (3, 10):
@overload
def entry_points() -> SelectableGroups: ... # type: ignore[overload-overlap]
def entry_points() -> SelectableGroups: ...
@overload
def entry_points(
*, name: str = ..., value: str = ..., group: str = ..., module: str = ..., attr: str = ..., extras: list[str] = ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/lib2to3/fixes/fix_unicode.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from ..pytree import Node

class FixUnicode(fixer_base.BaseFix):
BM_compatible: ClassVar[Literal[True]]
PATTERN: ClassVar[Literal["STRING | 'unicode' | 'unichr'"]] # type: ignore[name-defined] # Name "STRING" is not defined
PATTERN: ClassVar[str]
unicode_literals: bool
def start_tree(self, tree: Node, filename: StrPath) -> None: ...
def transform(self, node, results): ...
8 changes: 4 additions & 4 deletions stdlib/multiprocessing/sharedctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def copy(obj: _CT) -> _CT: ...
@overload
def synchronized(obj: _SimpleCData[_T], lock: _LockLike | None = None, ctx: Any | None = None) -> Synchronized[_T]: ...
@overload
def synchronized(obj: ctypes.Array[c_char], lock: _LockLike | None = None, ctx: Any | None = None) -> SynchronizedString: ... # type: ignore
def synchronized(obj: ctypes.Array[c_char], lock: _LockLike | None = None, ctx: Any | None = None) -> SynchronizedString: ...
@overload
def synchronized(
obj: ctypes.Array[_SimpleCData[_T]], lock: _LockLike | None = None, ctx: Any | None = None
Expand Down Expand Up @@ -115,12 +115,12 @@ class SynchronizedArray(SynchronizedBase[ctypes.Array[_SimpleCData[_T]]], Generi
class SynchronizedString(SynchronizedArray[bytes]):
@overload # type: ignore[override]
def __getitem__(self, i: slice) -> bytes: ...
@overload # type: ignore[override]
@overload
def __getitem__(self, i: int) -> bytes: ...
@overload # type: ignore[override]
def __setitem__(self, i: slice, value: bytes) -> None: ...
@overload # type: ignore[override]
def __setitem__(self, i: int, value: bytes) -> None: ... # type: ignore[override]
@overload
def __setitem__(self, i: int, value: bytes) -> None: ...
def __getslice__(self, start: int, stop: int) -> bytes: ... # type: ignore[override]
def __setslice__(self, start: int, stop: int, values: bytes) -> None: ... # type: ignore[override]

Expand Down
2 changes: 1 addition & 1 deletion stdlib/pdb.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Pdb(Bdb, Cmd):
def _runscript(self, filename: str) -> None: ...

if sys.version_info >= (3, 13):
def completedefault(self, text: str, line: str, begidx: int, endidx: int) -> list[str]: ... # type: ignore[override]
def completedefault(self, text: str, line: str, begidx: int, endidx: int) -> list[str]: ...

def do_commands(self, arg: str) -> bool | None: ...
def do_break(self, arg: str, temporary: bool = ...) -> bool | None: ...
Expand Down
18 changes: 11 additions & 7 deletions stdlib/re.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Match(Generic[AnyStr]):
@overload
def expand(self: Match[str], template: str) -> str: ...
@overload
def expand(self: Match[bytes], template: ReadableBuffer) -> bytes: ... # type: ignore[overload-overlap]
def expand(self: Match[bytes], template: ReadableBuffer) -> bytes: ...
@overload
def expand(self, template: AnyStr) -> AnyStr: ...
# group() returns "AnyStr" or "AnyStr | None", depending on the pattern.
Expand Down Expand Up @@ -124,19 +124,21 @@ class Pattern(Generic[AnyStr]):
@overload
def search(self: Pattern[str], string: str, pos: int = 0, endpos: int = sys.maxsize) -> Match[str] | None: ...
@overload
def search(self: Pattern[bytes], string: ReadableBuffer, pos: int = 0, endpos: int = sys.maxsize) -> Match[bytes] | None: ... # type: ignore[overload-overlap]
def search(self: Pattern[bytes], string: ReadableBuffer, pos: int = 0, endpos: int = sys.maxsize) -> Match[bytes] | None: ...
@overload
def search(self, string: AnyStr, pos: int = 0, endpos: int = sys.maxsize) -> Match[AnyStr] | None: ...
@overload
def match(self: Pattern[str], string: str, pos: int = 0, endpos: int = sys.maxsize) -> Match[str] | None: ...
@overload
def match(self: Pattern[bytes], string: ReadableBuffer, pos: int = 0, endpos: int = sys.maxsize) -> Match[bytes] | None: ... # type: ignore[overload-overlap]
def match(self: Pattern[bytes], string: ReadableBuffer, pos: int = 0, endpos: int = sys.maxsize) -> Match[bytes] | None: ...
@overload
def match(self, string: AnyStr, pos: int = 0, endpos: int = sys.maxsize) -> Match[AnyStr] | None: ...
@overload
def fullmatch(self: Pattern[str], string: str, pos: int = 0, endpos: int = sys.maxsize) -> Match[str] | None: ...
@overload
def fullmatch(self: Pattern[bytes], string: ReadableBuffer, pos: int = 0, endpos: int = sys.maxsize) -> Match[bytes] | None: ... # type: ignore[overload-overlap]
def fullmatch(
self: Pattern[bytes], string: ReadableBuffer, pos: int = 0, endpos: int = sys.maxsize
) -> Match[bytes] | None: ...
@overload
def fullmatch(self, string: AnyStr, pos: int = 0, endpos: int = sys.maxsize) -> Match[AnyStr] | None: ...
@overload
Expand All @@ -155,13 +157,15 @@ class Pattern(Generic[AnyStr]):
@overload
def finditer(self: Pattern[str], string: str, pos: int = 0, endpos: int = sys.maxsize) -> Iterator[Match[str]]: ...
@overload
def finditer(self: Pattern[bytes], string: ReadableBuffer, pos: int = 0, endpos: int = sys.maxsize) -> Iterator[Match[bytes]]: ... # type: ignore[overload-overlap]
def finditer(
self: Pattern[bytes], string: ReadableBuffer, pos: int = 0, endpos: int = sys.maxsize
) -> Iterator[Match[bytes]]: ...
@overload
def finditer(self, string: AnyStr, pos: int = 0, endpos: int = sys.maxsize) -> Iterator[Match[AnyStr]]: ...
@overload
def sub(self: Pattern[str], repl: str | Callable[[Match[str]], str], string: str, count: int = 0) -> str: ...
@overload
def sub( # type: ignore[overload-overlap]
def sub(
self: Pattern[bytes],
repl: ReadableBuffer | Callable[[Match[bytes]], ReadableBuffer],
string: ReadableBuffer,
Expand All @@ -172,7 +176,7 @@ class Pattern(Generic[AnyStr]):
@overload
def subn(self: Pattern[str], repl: str | Callable[[Match[str]], str], string: str, count: int = 0) -> tuple[str, int]: ...
@overload
def subn( # type: ignore[overload-overlap]
def subn(
self: Pattern[bytes],
repl: ReadableBuffer | Callable[[Match[bytes]], ReadableBuffer],
string: ReadableBuffer,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/tempfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class TemporaryDirectory(Generic[AnyStr]):

# The overloads overlap, but they should still work fine.
@overload
def mkstemp( # type: ignore[overload-overlap]
def mkstemp(
suffix: str | None = None, prefix: str | None = None, dir: StrPath | None = None, text: bool = False
) -> tuple[int, str]: ...
@overload
Expand All @@ -473,7 +473,7 @@ def mkstemp(

# The overloads overlap, but they should still work fine.
@overload
def mkdtemp(suffix: str | None = None, prefix: str | None = None, dir: StrPath | None = None) -> str: ... # type: ignore[overload-overlap]
def mkdtemp(suffix: str | None = None, prefix: str | None = None, dir: StrPath | None = None) -> str: ...
@overload
def mkdtemp(suffix: bytes | None = None, prefix: bytes | None = None, dir: BytesPath | None = None) -> bytes: ...
def mktemp(suffix: str = "", prefix: str = "tmp", dir: StrPath | None = None) -> str: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/tkinter/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3564,7 +3564,7 @@ class Spinbox(Widget, XView):
def scan_dragto(self, x): ...
def selection(self, *args) -> tuple[int, ...]: ...
def selection_adjust(self, index): ...
def selection_clear(self): ...
def selection_clear(self): ... # type: ignore[override]
def selection_element(self, element: Incomplete | None = None): ...
def selection_from(self, index: int) -> None: ...
def selection_present(self) -> None: ...
Expand Down
7 changes: 4 additions & 3 deletions stdlib/tkinter/ttk.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
@overload
def heading(self, column: str | int, option: str) -> Any: ...
@overload
def heading(self, column: str | int, option: None = None) -> _TreeviewHeaderDict: ... # type: ignore[overload-overlap]
def heading(self, column: str | int, option: None = None) -> _TreeviewHeaderDict: ...
@overload
def heading(
self,
Expand All @@ -1052,7 +1052,8 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
anchor: tkinter._Anchor = ...,
command: str | Callable[[], object] = ...,
) -> None: ...
def identify(self, component, x, y): ... # Internal Method. Leave untyped
# Internal Method. Leave untyped:
def identify(self, component, x, y): ... # type: ignore[override]
def identify_row(self, y: int) -> str: ...
def identify_column(self, x: int) -> str: ...
def identify_region(self, x: int, y: int) -> Literal["heading", "separator", "tree", "cell", "nothing"]: ...
Expand Down Expand Up @@ -1084,7 +1085,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
@overload
def item(self, item: str | int, option: str) -> Any: ...
@overload
def item(self, item: str | int, option: None = None) -> _TreeviewItemDict: ... # type: ignore[overload-overlap]
def item(self, item: str | int, option: None = None) -> _TreeviewItemDict: ...
@overload
def item(
self,
Expand Down
12 changes: 6 additions & 6 deletions stdlib/turtle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class TPen:
def isvisible(self) -> bool: ...
# Note: signatures 1 and 2 overlap unsafely when no arguments are provided
@overload
def pen(self) -> _PenState: ... # type: ignore[overload-overlap]
def pen(self) -> _PenState: ...
@overload
def pen(
self,
Expand Down Expand Up @@ -384,7 +384,7 @@ class RawTurtle(TPen, TNavigator):
def shape(self, name: str) -> None: ...
# Unsafely overlaps when no arguments are provided
@overload
def shapesize(self) -> tuple[float, float, float]: ... # type: ignore[overload-overlap]
def shapesize(self) -> tuple[float, float, float]: ...
@overload
def shapesize(
self, stretch_wid: float | None = None, stretch_len: float | None = None, outline: float | None = None
Expand All @@ -395,7 +395,7 @@ class RawTurtle(TPen, TNavigator):
def shearfactor(self, shear: float) -> None: ...
# Unsafely overlaps when no arguments are provided
@overload
def shapetransform(self) -> tuple[float, float, float, float]: ... # type: ignore[overload-overlap]
def shapetransform(self) -> tuple[float, float, float, float]: ...
@overload
def shapetransform(
self, t11: float | None = None, t12: float | None = None, t21: float | None = None, t22: float | None = None
Expand Down Expand Up @@ -622,7 +622,7 @@ def isvisible() -> bool: ...

# Note: signatures 1 and 2 overlap unsafely when no arguments are provided
@overload
def pen() -> _PenState: ... # type: ignore[overload-overlap]
def pen() -> _PenState: ...
@overload
def pen(
pen: _PenState | None = None,
Expand Down Expand Up @@ -661,7 +661,7 @@ if sys.version_info >= (3, 12):

# Unsafely overlaps when no arguments are provided
@overload
def shapesize() -> tuple[float, float, float]: ... # type: ignore[overload-overlap]
def shapesize() -> tuple[float, float, float]: ...
@overload
def shapesize(stretch_wid: float | None = None, stretch_len: float | None = None, outline: float | None = None) -> None: ...
@overload
Expand All @@ -671,7 +671,7 @@ def shearfactor(shear: float) -> None: ...

# Unsafely overlaps when no arguments are provided
@overload
def shapetransform() -> tuple[float, float, float, float]: ... # type: ignore[overload-overlap]
def shapetransform() -> tuple[float, float, float, float]: ...
@overload
def shapetransform(
t11: float | None = None, t12: float | None = None, t21: float | None = None, t22: float | None = None
Expand Down
6 changes: 3 additions & 3 deletions stdlib/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ class MappingProxyType(Mapping[_KT, _VT_co]):
def values(self) -> ValuesView[_VT_co]: ...
def items(self) -> ItemsView[_KT, _VT_co]: ...
@overload
def get(self, key: _KT, /) -> _VT_co | None: ... # type: ignore[override]
def get(self, key: _KT, /) -> _VT_co | None: ...
@overload
def get(self, key: _KT, default: _VT_co | _T2, /) -> _VT_co | _T2: ... # type: ignore[override]
def get(self, key: _KT, default: _VT_co | _T2, /) -> _VT_co | _T2: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __reversed__(self) -> Iterator[_KT]: ...
Expand Down Expand Up @@ -583,7 +583,7 @@ _P = ParamSpec("_P")

# it's not really an Awaitable, but can be used in an await expression. Real type: Generator & Awaitable
@overload
def coroutine(func: Callable[_P, Generator[Any, Any, _R]]) -> Callable[_P, Awaitable[_R]]: ... # type: ignore[overload-overlap]
def coroutine(func: Callable[_P, Generator[Any, Any, _R]]) -> Callable[_P, Awaitable[_R]]: ...
@overload
def coroutine(func: _Fn) -> _Fn: ...

Expand Down
2 changes: 1 addition & 1 deletion stdlib/unittest/mock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class _patcher:
# Ideally we'd be able to add an overload for it so that the return type is _patch[MagicMock],
# but that's impossible with the current type system.
@overload
def __call__( # type: ignore[overload-overlap]
def __call__(
self,
target: str,
new: _T,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/urllib/parse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ else:

# Requires an iterable of length 6
@overload
def urlunparse(components: Iterable[None]) -> Literal[b""]: ...
def urlunparse(components: Iterable[None]) -> Literal[b""]: ... # type: ignore[overload-overlap]
@overload
def urlunparse(components: Iterable[AnyStr | None]) -> AnyStr: ...

# Requires an iterable of length 5
@overload
def urlunsplit(components: Iterable[None]) -> Literal[b""]: ...
def urlunsplit(components: Iterable[None]) -> Literal[b""]: ... # type: ignore[overload-overlap]
@overload
def urlunsplit(components: Iterable[AnyStr | None]) -> AnyStr: ...
def unwrap(url: str) -> str: ...
2 changes: 1 addition & 1 deletion stubs/ExifRead/exifread/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from typing_extensions import Self
_T = TypeVar("_T")

@overload
def ord_(dta: str) -> int: ... # type: ignore[overload-overlap]
def ord_(dta: str) -> int: ...
@overload
def ord_(dta: _T) -> _T: ...
def make_string(seq: str | list[int]) -> str: ...
Expand Down
Loading

0 comments on commit 60f2ae3

Please sign in to comment.