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 on importing littlefs (from littlefs-python-0.10.0) #17059

Open
Krakonos opened this issue Mar 22, 2024 · 3 comments
Open

mypy crashes on importing littlefs (from littlefs-python-0.10.0) #17059

Krakonos opened this issue Mar 22, 2024 · 3 comments
Labels

Comments

@Krakonos
Copy link

Crash Report

I have a library, littlefs-python. Using it crashes mypy. A simple example with mypy-1.9.0 and littlefs-python-0.10.0:

#!/usr/bin/python

import littlefs

This seems to the offending definition:

class LFSStat(NamedTuple):
    type: int
    size: int
    name: str

    # Constants
    TYPE_REG: int = LFS_TYPE_REG
    TYPE_DIR: int = LFS_TYPE_DIR

And changing LFS_TYPE_REG & LFS_TYPE_DIR to an integer constant fixes the issue. It likely is a problem of the stub and I will report a separate bug to littlefs-python upstream, however, IMHO mypy should report this as a problem, not crash.

Traceback

Traceback (most recent call last):
  File "/usr/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/usr/lib/python3.11/site-packages/mypy/main.py", line 100, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/main.py", line 182, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/build.py", line 192, in build
    result = _build(
             ^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/build.py", line 266, in _build
    graph = dispatch(sources, manager, stdout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/build.py", line 2942, in dispatch
    process_graph(graph, manager)
  File "/usr/lib/python3.11/site-packages/mypy/build.py", line 3340, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/usr/lib/python3.11/site-packages/mypy/build.py", line 3467, in process_stale_scc
    graph[id].write_cache()
  File "/usr/lib/python3.11/site-packages/mypy/build.py", line 2503, in write_cache
    new_interface_hash, self.meta = write_cache(
                                    ^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/build.py", line 1564, in write_cache
    data = tree.serialize()
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/nodes.py", line 387, in serialize
    "names": self.names.serialize(self._fullname),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/nodes.py", line 3933, in serialize
    data[key] = value.serialize(fullname, key)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/nodes.py", line 3870, in serialize
    data["node"] = self.node.serialize()
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/nodes.py", line 3278, in serialize
    "names": self.names.serialize(self.fullname),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/nodes.py", line 3933, in serialize
    data[key] = value.serialize(fullname, key)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mypy/nodes.py", line 3865, in serialize
    assert not isinstance(
AssertionError: Definition of littlefs.lfs.LFSStat.TYPE_REG is unexpectedly incomplete

To Reproduce

See snippet above.

Your Environment

  • Mypy version used: 1.9.0 (from system Arch Linux)
  • Mypy command-line flags: none (mypy foo.py)
  • Mypy configuration options from mypy.ini (and other config files): no config present
  • Python version used: 3.11.8
  • Operating system and version: Arch Linux, current system as of 2024-03-22
@Krakonos Krakonos added the crash label Mar 22, 2024
Krakonos added a commit to Krakonos/littlefs-python that referenced this issue Mar 22, 2024
It seems all versions of mypy between 1.0.1 and 1.9.0 crash due to this
definition ( python/mypy#17059 ).
@ethanhs
Copy link
Collaborator

ethanhs commented Mar 22, 2024

Littlefs seems to be a C library, could you link to what stubs you are using, I don't see any in the project github.

@hauntsaninja
Copy link
Collaborator

@Krakonos
Copy link
Author

Correct, this is the stub. Note that the version 0.10.1 fixes this stub, so use 0.10.0 for reproduction.

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