From eb6d70bc8b43506775f0fd1a1bef4dd9793053ce Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 8 May 2026 13:57:44 +0200 Subject: [PATCH 1/6] Update mypy to 2.0.0 Remove command line options that are now the default. --- requirements-tests.txt | 2 +- tests/typecheck_typeshed.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 059b8dc6d2fa..54777c2071e3 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,6 +1,6 @@ # Type checkers that we test our stubs against. These should always # be pinned to a specific version to make failure reproducible. -mypy==1.20.0 +mypy==2.0.0 pyright==1.1.408 # Libraries used by our various scripts. diff --git a/tests/typecheck_typeshed.py b/tests/typecheck_typeshed.py index 6ddbb90a8a5b..de9d8cee7d59 100755 --- a/tests/typecheck_typeshed.py +++ b/tests/typecheck_typeshed.py @@ -55,8 +55,6 @@ def run_mypy_as_subprocess(directory: str, platform: str, version: str) -> Retur "--python-version", version, "--strict", - "--strict-bytes", - "--local-partial-types", "--pretty", "--show-traceback", "--no-error-summary", From e43ad3da3dde40b7847c5249e6841e19b515d36e Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 8 May 2026 14:03:04 +0200 Subject: [PATCH 2/6] [lupa] Fix incompatible default value errors --- stubs/lupa/lupa/lua51.pyi | 2 +- stubs/lupa/lupa/lua52.pyi | 2 +- stubs/lupa/lupa/lua53.pyi | 2 +- stubs/lupa/lupa/lua54.pyi | 2 +- stubs/lupa/lupa/luajit20.pyi | 2 +- stubs/lupa/lupa/luajit21.pyi | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stubs/lupa/lupa/lua51.pyi b/stubs/lupa/lupa/lua51.pyi index 768251730bff..7604148b370b 100644 --- a/stubs/lupa/lupa/lua51.pyi +++ b/stubs/lupa/lupa/lua51.pyi @@ -66,7 +66,7 @@ _bint = TypeVar("_bint", bool, int) class FastRLock(Generic[_bint]): # @classmethod # def __init__(cls, /, *args: Any, **kwargs: Any) -> None: ... - def acquire(self, blocking: _bint = True) -> _bint: ... + def acquire(self, blocking: _bint = ...) -> _bint: ... def release(self) -> None: ... def __enter__(self) -> _bint: ... def __exit__(self, t: object, v: object, tb: object) -> None: ... diff --git a/stubs/lupa/lupa/lua52.pyi b/stubs/lupa/lupa/lua52.pyi index 768251730bff..7604148b370b 100644 --- a/stubs/lupa/lupa/lua52.pyi +++ b/stubs/lupa/lupa/lua52.pyi @@ -66,7 +66,7 @@ _bint = TypeVar("_bint", bool, int) class FastRLock(Generic[_bint]): # @classmethod # def __init__(cls, /, *args: Any, **kwargs: Any) -> None: ... - def acquire(self, blocking: _bint = True) -> _bint: ... + def acquire(self, blocking: _bint = ...) -> _bint: ... def release(self) -> None: ... def __enter__(self) -> _bint: ... def __exit__(self, t: object, v: object, tb: object) -> None: ... diff --git a/stubs/lupa/lupa/lua53.pyi b/stubs/lupa/lupa/lua53.pyi index 768251730bff..7604148b370b 100644 --- a/stubs/lupa/lupa/lua53.pyi +++ b/stubs/lupa/lupa/lua53.pyi @@ -66,7 +66,7 @@ _bint = TypeVar("_bint", bool, int) class FastRLock(Generic[_bint]): # @classmethod # def __init__(cls, /, *args: Any, **kwargs: Any) -> None: ... - def acquire(self, blocking: _bint = True) -> _bint: ... + def acquire(self, blocking: _bint = ...) -> _bint: ... def release(self) -> None: ... def __enter__(self) -> _bint: ... def __exit__(self, t: object, v: object, tb: object) -> None: ... diff --git a/stubs/lupa/lupa/lua54.pyi b/stubs/lupa/lupa/lua54.pyi index 768251730bff..7604148b370b 100644 --- a/stubs/lupa/lupa/lua54.pyi +++ b/stubs/lupa/lupa/lua54.pyi @@ -66,7 +66,7 @@ _bint = TypeVar("_bint", bool, int) class FastRLock(Generic[_bint]): # @classmethod # def __init__(cls, /, *args: Any, **kwargs: Any) -> None: ... - def acquire(self, blocking: _bint = True) -> _bint: ... + def acquire(self, blocking: _bint = ...) -> _bint: ... def release(self) -> None: ... def __enter__(self) -> _bint: ... def __exit__(self, t: object, v: object, tb: object) -> None: ... diff --git a/stubs/lupa/lupa/luajit20.pyi b/stubs/lupa/lupa/luajit20.pyi index 5e5009bb287f..fdf3fe3d448e 100644 --- a/stubs/lupa/lupa/luajit20.pyi +++ b/stubs/lupa/lupa/luajit20.pyi @@ -59,7 +59,7 @@ _bint = TypeVar("_bint", bool, int) class FastRLock(Generic[_bint]): # @classmethod # def __init__(cls, /, *args: Any, **kwargs: Any) -> None: ... - def acquire(self, blocking: _bint = True) -> _bint: ... + def acquire(self, blocking: _bint = ...) -> _bint: ... def release(self) -> None: ... def __enter__(self) -> _bint: ... def __exit__(self, t: object, v: object, tb: object) -> None: ... diff --git a/stubs/lupa/lupa/luajit21.pyi b/stubs/lupa/lupa/luajit21.pyi index 5e5009bb287f..fdf3fe3d448e 100644 --- a/stubs/lupa/lupa/luajit21.pyi +++ b/stubs/lupa/lupa/luajit21.pyi @@ -59,7 +59,7 @@ _bint = TypeVar("_bint", bool, int) class FastRLock(Generic[_bint]): # @classmethod # def __init__(cls, /, *args: Any, **kwargs: Any) -> None: ... - def acquire(self, blocking: _bint = True) -> _bint: ... + def acquire(self, blocking: _bint = ...) -> _bint: ... def release(self) -> None: ... def __enter__(self) -> _bint: ... def __exit__(self, t: object, v: object, tb: object) -> None: ... From 66093aeab701decd2a87b0eb0096deb7d8c6db8f Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 8 May 2026 14:23:58 +0200 Subject: [PATCH 3/6] [pdf2] Add `bytearray` to a few argument types --- stubs/fpdf2/fpdf/encryption.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/fpdf2/fpdf/encryption.pyi b/stubs/fpdf2/fpdf/encryption.pyi index a41ecbc93b4d..542c931e0de1 100644 --- a/stubs/fpdf2/fpdf/encryption.pyi +++ b/stubs/fpdf2/fpdf/encryption.pyi @@ -87,10 +87,10 @@ class StandardSecurityHandler: @overload def encrypt(self, text: str, obj_id: int) -> str: ... def encrypt_string(self, string: str, obj_id: int) -> str: ... - def encrypt_stream(self, stream: bytes, obj_id: int) -> bytes: ... + def encrypt_stream(self, stream: bytes | bytearray, obj_id: int) -> bytes: ... def is_aes_algorithm(self) -> bool: ... - def encrypt_bytes(self, data: bytes, obj_id: int) -> list[int]: ... - def encrypt_AES_cryptography(self, key: bytes, data: bytes) -> bytes: ... + def encrypt_bytes(self, data: bytes | bytearray, obj_id: int) -> list[int]: ... + def encrypt_AES_cryptography(self, key: bytes, data: bytes | bytearray) -> bytes: ... @classmethod def get_random_bytes(cls, size: int) -> bytes: ... @classmethod @@ -99,7 +99,7 @@ class StandardSecurityHandler: def generate_owner_password(self) -> str: ... def generate_user_password(self) -> str: ... @classmethod - def compute_hash(cls, input_password: bytes, salt: bytes, user_key: bytes = ...) -> bytes: ... + def compute_hash(cls, input_password: bytes | bytearray, salt: bytes, user_key: bytes | bytearray = ...) -> bytes: ... def generate_user_password_rev6(self) -> None: ... def generate_owner_password_rev6(self) -> None: ... def generate_perms_rev6(self) -> None: ... From cdbf74191252068f81efd6b2557e14cfcf73a166 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 8 May 2026 14:44:09 +0200 Subject: [PATCH 4/6] Try avoiding race conditions --- tests/regr_test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/regr_test.py b/tests/regr_test.py index 39381c676062..2adc9915a16d 100755 --- a/tests/regr_test.py +++ b/tests/regr_test.py @@ -175,7 +175,7 @@ def run_testcases( else: configurations = mypy_configuration_from_distribution(package.name) - with temporary_mypy_config_file(configurations) as temp: + with temporary_mypy_config_file(configurations) as temp_config, tempfile.TemporaryDirectory() as temp_cache_dir: # "--enable-error-code ignore-without-code" is purposefully omitted. # See https://github.com/python/typeshed/pull/8083 @@ -189,10 +189,14 @@ def run_testcases( "--strict", "--pretty", "--config-file", - temp.name, + temp_config.name, # Avoid race conditions when reading the cache # (https://github.com/python/typeshed/issues/11220) "--no-incremental", + # Avoid race conditions even harder + # https://github.com/python/mypy/issues/13916 + "--cache-dir", + temp_cache_dir, # Not useful for the test cases "--disable-error-code=empty-body", ] From 7414f99795b1ac63f3b262fb546b9b56de802b6d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 8 May 2026 15:01:50 +0200 Subject: [PATCH 5/6] Reenable an error code that was previously disabled --- tests/typecheck_typeshed.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/typecheck_typeshed.py b/tests/typecheck_typeshed.py index de9d8cee7d59..90fcd7e4249f 100755 --- a/tests/typecheck_typeshed.py +++ b/tests/typecheck_typeshed.py @@ -60,9 +60,8 @@ def run_mypy_as_subprocess(directory: str, platform: str, version: str) -> Retur "--no-error-summary", "--enable-error-code", "ignore-without-code", - # https://github.com/python/mypy/issues/14309 - # "--enable-error-code", - # "possibly-undefined", + "--enable-error-code", + "possibly-undefined", "--enable-error-code", "redundant-expr", "--enable-error-code", From f25b7330b49b8667c31590c6ae7ded83bf1e0da0 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 8 May 2026 15:10:35 +0200 Subject: [PATCH 6/6] Remove --no-incremental --- tests/regr_test.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/regr_test.py b/tests/regr_test.py index 2adc9915a16d..510b6fff8d59 100755 --- a/tests/regr_test.py +++ b/tests/regr_test.py @@ -190,10 +190,7 @@ def run_testcases( "--pretty", "--config-file", temp_config.name, - # Avoid race conditions when reading the cache - # (https://github.com/python/typeshed/issues/11220) - "--no-incremental", - # Avoid race conditions even harder + # Avoid race conditions when using the cache # https://github.com/python/mypy/issues/13916 "--cache-dir", temp_cache_dir,