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

"AttributeError: 'int' object has no attribute 'is_meta_var'" in 1.11 #17516

Closed
Redoubts opened this issue Jul 11, 2024 · 5 comments
Closed

"AttributeError: 'int' object has no attribute 'is_meta_var'" in 1.11 #17516

Redoubts opened this issue Jul 11, 2024 · 5 comments
Labels

Comments

@Redoubts
Copy link

Bug Report

I pip-installed the 1.11 branch to take a preview of the next release, and I saw a crash when running mypy:

pip install -U git+https://github.com/python/mypy.git@release-1.11

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "<my-venv>/lib/python3.11/site-packages/mypy/__main__.py", line 37, in <module>
    console_entry()
  File "<my-venv>/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "<my-venv>/lib/python3.11/site-packages/mypy/main.py", line 103, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/main.py", line 187, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/build.py", line 193, in build
    result = _build(
             ^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/build.py", line 268, in _build
    graph = dispatch(sources, manager, stdout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/build.py", line 2950, in dispatch
    process_graph(graph, manager)
  File "<my-venv>/lib/python3.11/site-packages/mypy/build.py", line 3348, in process_graph
    process_stale_scc(graph, scc, manager)
  File "<my-venv>/lib/python3.11/site-packages/mypy/build.py", line 3475, in process_stale_scc
    graph[id].write_cache()
  File "<my-venv>/lib/python3.11/site-packages/mypy/build.py", line 2507, in write_cache
    new_interface_hash, self.meta = write_cache(
                                    ^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/build.py", line 1568, in write_cache
    data = tree.serialize()
           ^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/nodes.py", line 390, in serialize
    "names": self.names.serialize(self._fullname),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/nodes.py", line 4012, in serialize
    data[key] = value.serialize(fullname, key)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/nodes.py", line 3949, in serialize
    data["node"] = self.node.serialize()
                   ^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/nodes.py", line 3351, in serialize
    "names": self.names.serialize(self.fullname),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/nodes.py", line 4012, in serialize
    data[key] = value.serialize(fullname, key)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/nodes.py", line 3949, in serialize
    data["node"] = self.node.serialize()
                   ^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/nodes.py", line 935, in serialize
    "var": self.var.serialize(),
           ^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/nodes.py", line 1081, in serialize
    "type": None if self.type is None else self.type.serialize(),
                                           ^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/types.py", line 2335, in serialize
    return {".class": "Overloaded", "items": [t.serialize() for t in self.items]}
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/types.py", line 2335, in <listcomp>
    return {".class": "Overloaded", "items": [t.serialize() for t in self.items]}
                                              ^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/types.py", line 2223, in serialize
    "arg_types": [t.serialize() for t in self.arg_types],
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/types.py", line 2223, in <listcomp>
    "arg_types": [t.serialize() for t in self.arg_types],
                  ^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/types.py", line 2223, in serialize
    "arg_types": [t.serialize() for t in self.arg_types],
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/types.py", line 2223, in <listcomp>
    "arg_types": [t.serialize() for t in self.arg_types],
                  ^^^^^^^^^^^^^
  File "<my-venv>/lib/python3.11/site-packages/mypy/types.py", line 663, in serialize
    assert not self.id.is_meta_var()
               ^^^^^^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'is_meta_var'

To Reproduce

Hard to share, this happens when running on my company code. Can look more closely by request, if the traceback isn't enough.

Expected Behavior

No traceback from mypy

Actual Behavior

(See traceback)

Your Environment

  • Mypy version used: 1.11 pre-release
  • Python version used: 3.11 on debian
@Redoubts Redoubts added the bug mypy got something wrong label Jul 11, 2024
@sobolevn
Copy link
Member

Reproducer is needed 🙏

@AlexWaygood AlexWaygood added crash and removed bug mypy got something wrong labels Jul 11, 2024
@hauntsaninja
Copy link
Collaborator

That's strange and concerning

@cdce8p
Copy link
Collaborator

cdce8p commented Jul 12, 2024

This looks like it's related to an overload with a TypeVar. Do you use custom mypy plugins? Maybe the one for pydantic? The TypeVar.id was changed this release cycle to only accept TypeVarId types, no longer ints. If a plugin isn't updated, that might cause the issue / crash. However, to say for sure, we need a reproducer.

For pydantic v1: make sure to run at least >=1.10.16 as that's the "fixed" version.
https://github.com/pydantic/pydantic/releases/tag/v1.10.16

@Redoubts
Copy link
Author

It's definitely a plugin. Looks like this will stop crashing if I turn off trio-typing. I'll close this as this feels like a 3rd party problem, though I wonder if there's a way for mypy to better blame a plugin for things like this. I think I've been burned by a plugin that doesn't work well with a newer mypy before, and it always feels as inscrutable.

@antoninkriz
Copy link

antoninkriz commented Jul 24, 2024

@cdce8p Hello, shouldn't this change be reflected in the "Announcement issue for plugin API changes" #6617 issue?
Currently a plugin I maintain fails after updating the mypy dependency since we use integers in the id parameter in mypy.types.TypeVarType(...).
I guess the change won't be too difficult since we just use -1 as the int value, but it still breaks the plugin.
Thank you!

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

6 participants