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

Mypy crashes with 1.11.1 version and Pydantic 1.10.11 #17671

Closed
OmerFI opened this issue Aug 13, 2024 · 3 comments
Closed

Mypy crashes with 1.11.1 version and Pydantic 1.10.11 #17671

OmerFI opened this issue Aug 13, 2024 · 3 comments
Labels

Comments

@OmerFI
Copy link

OmerFI commented Aug 13, 2024

Crash Report

Updated mypy to 1.11.1 version. Run mypy and faced with error.
It doesn't crash with mypy 1.10.1

Traceback

❯ mypy xxx/ --show-traceback
/home/omerfi/xxx/.venv/lib/python3.10/site-packages/pydantic/env_settings.py:23: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.11.1
Traceback (most recent call last):
  File "mypy/semanal.py", line 7092, in accept
  File "mypy/nodes.py", line 1183, in accept
  File "mypy/semanal.py", line 1700, in visit_class_def
  File "mypy/semanal.py", line 1891, in analyze_class
  File "mypy/semanal.py", line 1925, in analyze_class_body_common
  File "mypy/semanal.py", line 2010, in apply_class_plugin_hooks
  File "pydantic/mypy.py", line 154, in pydantic.mypy.PydanticPlugin._pydantic_model_class_maker_callback
  File "pydantic/mypy.py", line 317, in pydantic.mypy.PydanticModelTransformer.transform
  File "pydantic/mypy.py", line 497, in pydantic.mypy.PydanticModelTransformer.add_construct_method
  File "mypy/types.py", line 607, in __init__
TypeError: mypy.types.TypeVarId object expected; got int
/home/omerfi/xxx/.venv/lib/python3.10/site-packages/pydantic/env_settings.py:23: : note: use --pdb to drop into pdb

To Reproduce

I created a POC repository. You can follow the instructions in the README and face the error yourself: https://github.com/OmerFI/mypyfailproject

Your Environment

@OmerFI OmerFI added the crash label Aug 13, 2024
@OmerFI OmerFI changed the title Mypy fails with 1.11.1 version and Pydantic 1.10.11 Mypy crashes with 1.11.1 version and Pydantic 1.10.11 Aug 13, 2024
@ilevkivskyi
Copy link
Member

This should be reported to pydantic instead: plain integers as type variable IDs are not supported anymore (plain integers are kind of private API anyway).

@ilevkivskyi ilevkivskyi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2024
@OmerFI
Copy link
Author

OmerFI commented Aug 14, 2024

Interesting,
it works with mypy 1.10 and you publish a release, everything breaks and you say its pydantic's issue.
you should change the description btw it points to mypy issues:

❯ mypy xxx/ --show-traceback
/home/omerfi/xxx/.venv/lib/python3.10/site-packages/pydantic/env_settings.py:23: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 14, 2024

The plugin is run within the mypy process, so each traceback that has entries related to plugins needs to be investigated to determine the correct root cause.

In this case it seems clear that mypy changed an internal API, and the plugin may need to switch to the new API (i.e. using TypeVarId). This was changed in #17311. Replacing integer ids with TypeVarId(id) could be enough to avoid the crash, but additional adjustments may be required to avoid type variable conflicts. Refer to #17311 for more details. This PR fixed some long-standing issues with how mypy deals with type variables, and this required dropping support for integer ids.

As the plugin system doesn't guarantee backward compatibility, my suggestion would be to test plugins using mypy master in addition to the most recent release to catch issue like this earlier. Also, we could document internal changes in #6617 more widely, but it's hard to predict which internal changes could impact plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants