Skip to content
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

Bump mypy to 1.6.1 #10862

Merged
merged 4 commits into from
Oct 18, 2023
Merged

Bump mypy to 1.6.1 #10862

merged 4 commits into from
Oct 18, 2023

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Oct 10, 2023

There's a few more stubtest allowlist entries now, due to a new check where stubtest emits an error if a stdlib module exists at runtime, but isn't present in the stubs.

I'm not sure what's going on with all the new stubtest errors on _dummy_threading on py38. But it's an internal module that was removed in py39, so I don't think it matters too much.

@AlexWaygood
Copy link
Member Author

Hum, looks like mypy==1.6.0 is crashing on our Flask-SocketIO stubs without printing any traceback to the terminal. You can see that in our CI; I can also reproduce by creating a new virtual environment, then running these steps:

$ pip install "mypy==1.6.0" "Flask>=0.9" --no-cache-dir
$ python -m mypy --python-version 3.12 --show-traceback --warn-incomplete-stub --no-error-summary --platform win32 --custom-typeshed-dir . --strict --allow-untyped-defs --allow-incomplete-defs --allow-subclassing-any --enable-error-code ignore-without-code --explicit-package-bases stubs\Flask-SocketIO\flask_socketio\__init__.pyi stubs\Flask-SocketIO\flask_socketio\namespace.pyi stubs\Flask-SocketIO\flask_socketio\test_client.pyi

@AlexWaygood
Copy link
Member Author

AlexWaygood commented Oct 10, 2023

Hum, looks like mypy==1.6.0 is crashing on our Flask-SocketIO stubs without printing any traceback to the terminal. You can see that in our CI;

Hmmmmm, well, mypy_test.py is behaving oddly here: it's reporting that running mypy on Flask-SocketIO was a failure, but then marks the whole job overall as a "success" and exits with code 0: https://github.com/python/typeshed/actions/runs/6475810432/job/17583489154?pr=10862

Third-party stubtest is still giving exit code 1 due to the crash, though: https://github.com/python/typeshed/actions/runs/6475810434/job/17583487385?pr=10862

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member Author

I'll investigate more in the morning; it's late here now. Seems like both mypy and mypy_test.py are buggy here.

@AlexWaygood
Copy link
Member Author

Hmmmmm, well, mypy_test.py is behaving oddly here: it's reporting that running mypy on Flask-SocketIO was a failure, but then marks the whole job overall as a "success" and exits with code 0: https://github.com/python/typeshed/actions/runs/6475810432/job/17583489154?pr=10862

I can't reproduce this behaviour locally. If I run mypy_test.py locally with mypy==1.6.0 installed, the script fails correctly due to the crash in Flask-SocketIO:

Script output:
>python tests/mypy_test.py -p3.12
*** Testing Python 3.12 on win32
Testing stdlib (494 files)...success

Testing third-party packages...
testing Deprecated (3 files)... success
testing ExifRead (17 files)... success
testing Flask-Cors (5 files)... success
testing Flask-Migrate (1 files)... success
testing Flask-SocketIO (3 files)... failure

C:\Users\alexw\AppData\Local\Temp\tmpxqy0ou3o: No [mypy] section in config file

testing JACK-Client (1 files)... success
testing Markdown (30 files)... success
testing Pillow (92 files)... success
testing PyAutoGUI (1 files)... success
testing PyMySQL (16 files)... success
testing PyScreeze (1 files)... success
testing PyYAML (18 files)... success
testing Pygments (31 files)... success
testing Send2Trash (4 files)... success
testing WTForms (19 files)... success
testing WebOb (17 files)... success
testing aiofiles (10 files)... success
testing aws-xray-sdk (52 files)... success
testing beautifulsoup4 (9 files)... success
testing bleach (6 files)... success
testing boltons (30 files)... success
testing boto (31 files)... success
testing braintree (154 files)... success
testing cachetools (3 files)... success
testing caldav (14 files)... success
testing cffi (17 files)... success
testing chevron (5 files)... success
testing click-default-group (1 files)... success
testing click-spinner (2 files)... success
testing colorama (6 files)... success
testing commonmark (14 files)... success
testing console-menu (24 files)... success
testing croniter (2 files)... success
testing dateparser (32 files)... success
testing decorator (1 files)... success
testing dockerfile-parse (4 files)... success
testing docopt (1 files)... success
testing docutils (41 files)... success
testing editdistance (1 files)... success
testing entrypoints (1 files)... success
testing first (1 files)... success
testing flake8-2020 (1 files)... success
testing flake8-bugbear (1 files)... success
testing flake8-builtins (1 files)... success
testing flake8-docstrings (1 files)... success
testing flake8-plugin-utils (6 files)... success
testing flake8-rst-docstrings (1 files)... success
testing flake8-simplify (1 files)... success
testing flake8-typing-imports (1 files)... success
testing fpdf2 (28 files)... success
testing gdb (7 files)... success
testing google-cloud-ndb (23 files)... success
testing greenlet (2 files)... success
testing hdbcli (3 files)... success
testing html5lib (33 files)... success
testing httplib2 (6 files)... success
testing humanfriendly (15 files)... success
testing ibm-db (1 files)... success
testing influxdb-client (405 files)... success
testing inifile (1 files)... success
testing invoke (21 files)... success
testing jmespath (8 files)... success
testing jsonschema (11 files)... success
testing keyboard (6 files)... success
testing ldap3 (110 files)... success
testing libsass (5 files)... success
testing mock (3 files)... success
testing mypy-extensions (1 files)... success
testing mysqlclient (14 files)... success
testing netaddr (20 files)... success
testing oauthlib (64 files)... success
testing openpyxl (190 files)... success
testing opentracing (26 files)... success
testing paho-mqtt (10 files)... success
testing paramiko (46 files)... success
testing parsimonious (6 files)... success
testing passlib (61 files)... success
testing passpy (4 files)... success
testing peewee (1 files)... success
testing pep8-naming (1 files)... success
testing pexpect (15 files)... success
testing pika (30 files)... success
testing playsound (1 files)... success
testing pluggy (5 files)... success
testing polib (1 files)... success
testing protobuf (37 files)... success
testing psutil (14 files)... success
testing psycopg2 (12 files)... success
testing pyOpenSSL (5 files)... success
testing pyRFC3339 (4 files)... success
testing pyasn1 (33 files)... success
testing pyaudio (1 files)... success
testing pycocotools (4 files)... success
testing pycurl (1 files)... success
testing pyfarmhash (1 files)... success
testing pyflakes (5 files)... success
testing pyinstaller (21 files)... success
testing pyjks (7 files)... success
testing pynput (9 files)... success
testing pyserial (28 files)... success
testing pysftp (3 files)... success
testing pytest-lazy-fixture (1 files)... success
testing python-crontab (3 files)... success
testing python-datemath (2 files)... success
testing python-dateutil (13 files)... success
testing python-gflags (1 files)... success
testing python-jose (15 files)... success
testing python-nmap (2 files)... success
testing python-slugify (4 files)... success
testing python-xlib (66 files)... success
testing pytz (6 files)... success
testing pyvmomi (9 files)... success
testing pywin32 (243 files)... success
testing qrcode (21 files)... success
testing redis (53 files)... success
testing regex (4 files)... success
testing requests (17 files)... success
testing requests-oauthlib (15 files)... success
testing retry (2 files)... success
testing s2clientprotocol (11 files)... success
testing setuptools (82 files)... success
testing simplejson (6 files)... success
testing singledispatch (1 files)... success
testing six (42 files)... success
testing slumber (4 files)... success
testing stdlib-list (3 files)... success
testing stripe (127 files)... success
testing tabulate (2 files)... success
testing tensorflow (110 files)... success
testing toml (5 files)... success
testing toposort (1 files)... success
testing tqdm (31 files)... success
testing translationstring (1 files)... success
testing tree-sitter (2 files)... success
testing tree-sitter-languages (2 files)... success
testing ttkthemes (6 files)... success
testing tzlocal (3 files)... success
testing uWSGI (2 files)... success
testing ujson (1 files)... success
testing untangle (1 files)... success
testing usersettings (1 files)... success
testing vobject (9 files)... success
testing waitress (15 files)... success
testing whatthepatch (5 files)... success
testing workalendar (150 files)... success
testing xmltodict (1 files)... success
testing zstd (1 files)... success
testing zxcvbn (7 files)... success

--- exit status 3221225725, 3706 files checked ---

@srittau
Copy link
Collaborator

srittau commented Oct 11, 2023

It also fails for me locally (Python 3.11.4, Ubuntu):

(.venv) srittau@blitz:~/Projekte/typeshed$ python tests/mypy_test.py -p3.12
*** Testing Python 3.12 on linux
Testing stdlib (494 files)...success

Testing third-party packages...
testing Deprecated (3 files)... success
testing ExifRead (17 files)... success
testing Flask-Cors (5 files)... success
testing Flask-Migrate (1 files)... success
testing Flask-SocketIO (3 files)... failure

testing JACK-Client (1 files)... success
testing Markdown (30 files)... success
testing Pillow (92 files)... success
testing PyAutoGUI (1 files)... success
[...]
testing xmltodict (1 files)... success
testing zstd (1 files)... success
testing zxcvbn (7 files)... success

--- success, 3706 files checked ---

I'll see if I can find anything.

@AlexWaygood
Copy link
Member Author

I minimised the mypy crash:

But don't know what's going on with mypy_test.py.

@srittau
Copy link
Collaborator

srittau commented Oct 11, 2023

The problem with mypy_test was that mypy returned exit code -11, but mypy_test was combining exit codes using code = max(code, this_code), so the exit code could never be < 0.

#10866

@AlexWaygood
Copy link
Member Author

The problem with mypy_test was that mypy returned exit code -11, but mypy_test was combining exit codes using code = max(code, this_code), so the exit code could never be < 0.

#10866

Great find. And, interesting! Locally, I was getting exit code 3221225725.

@srittau
Copy link
Collaborator

srittau commented Oct 11, 2023

Nice(?!), it fails now.

@AlexWaygood
Copy link
Member Author

Nice(?!), it fails now.

Yes -- hooray(??) -- we now correctly get 15 more CI errors

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member Author

This diff works around the mypy crash, with only a very minor readability cost:

--- a/stubs/Flask-SocketIO/flask_socketio/__init__.pyi
+++ b/stubs/Flask-SocketIO/flask_socketio/__init__.pyi
@@ -13,10 +13,9 @@ from .test_client import SocketIOTestClient
 _P = ParamSpec("_P")
 _R_co = TypeVar("_R_co", covariant=True)
 _ExceptionHandler: TypeAlias = Callable[[BaseException], _R_co]
-_Handler: TypeAlias = Callable[_P, _R_co]

 class _HandlerDecorator(Protocol):
-    def __call__(self, handler: _Handler[_P, _R_co]) -> _Handler[_P, _R_co]: ...
+    def __call__(self, handler: Callable[_P, _R_co]) -> Callable[_P, _R_co]: ...

 class _ExceptionHandlerDecorator(Protocol):
     def __call__(self, exception_handler: _ExceptionHandler[_R_co]) -> _ExceptionHandler[_R_co]: ...
@@ -52,9 +51,9 @@ class SocketIO:
     def on(self, message: str, namespace: str | None = None) -> _HandlerDecorator: ...
     def on_error(self, namespace: str | None = None) -> _ExceptionHandlerDecorator: ...
     def on_error_default(self, exception_handler: _ExceptionHandler[_R_co]) -> _ExceptionHandler[_R_co]: ...
-    def on_event(self, message: str, handler: _Handler[[Incomplete], object], namespace: str | None = None) -> None: ...
+    def on_event(self, message: str, handler: Callable[[Incomplete], object], namespace: str | None = None) -> None: ...
     @overload
-    def event(self, __event_handler: _Handler[_P, _R_co]) -> _Handler[_P, _R_co]: ...
+    def event(self, __event_handler: Callable[_P, _R_co]) -> Callable[_P, _R_co]: ...
     @overload
     def event(self, namespace: str | None = None, *args, **kwargs) -> _HandlerDecorator: ...
     def on_namespace(self, namespace_handler: Namespace) -> None: ...

Two other options are:
2. Temporarily skip running mypy/stubtest on Flask-SocketIO
3. Just wait until the mypy bug is fixed before we upgrade mypy

What do we like the sound of best?

@JelleZijlstra
Copy link
Member

Since it's quite likely that we'll get a mypy 1.6.1 in a few days fixing the crash, I think we should wait at least a little.

@JelleZijlstra
Copy link
Member

The problem with mypy_test was that mypy returned exit code -11, but mypy_test was combining exit codes using code = max(code, this_code), so the exit code could never be < 0.

Note that -11 is a segfault (on Unix). That explains why Alex saw something different on Windows. I would expect something like python/mypy#16245 to result in a segfault when mypy is compiled with mypyc; @AlexWaygood presumably got the repro case there by using uncompiled mypy.

@AlexWaygood
Copy link
Member Author

@AlexWaygood presumably got the repro case there by using uncompiled mypy.

Yes, I only got the stack trace using uncompiled mypy (using the master branch). Using compiled mypy==1.6.0, I got the same output we're getting in CI here (i.e., nothing!), but with return code 3221225725

@AlexWaygood AlexWaygood changed the title Bump mypy to 1.6.0 Bump mypy to 1.6.1 Oct 18, 2023
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood AlexWaygood merged commit 2f8d01e into python:main Oct 18, 2023
@AlexWaygood AlexWaygood deleted the bump-mypy branch October 18, 2023 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants