Transformers crashes mypy
See original GitHub issueUbuntu 21.04, tested on both Python 3.8 and Python 3.9 with mypy 0.910
I get a crash caused by transformers 4.10.0
when typechecking a private codebase which imports transformers. This is the error message:
src/transformers/trainer.py:1435: 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: 0.910
(I also get the crash trying mypy master. I’m going to submit a corresponding bug report directly to the mypy issue tracker.)
This is the corresponding line:
That method is imported into the class, which presumably upsets mypy somehow.
Repro
I can reproduce this locally in the following way:
- Clone the transformers repo
- Create a blank virtualenv and install mypy 0.910
- Add the following
mypy.ini
file:[mypy] check_untyped_defs=True
- Run
mypy src/transformers/trainer.py
Confusingly, this local repro method also crashes mypy when using the 4.9.1 tag, but I don’t experience the crash in my private codebase when using that transformers version 🤷
cc @sgugger
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Crash when typechecking transformers 4.10.0 #11045 - GitHub
Crash Report I am typechecking a codebase which imports transformers 4.10.0 and hitting a mypy internal error.
Read more >MyPy crashes due to syntax error in underlying modules
I'm trying to run MyPy on my package, but I'm running into issues due to a syntax error in an underlying package, that...
Read more >PC crashes and turns off when using large hidden size - PyTorch ...
Hello, I'm trying to replicate the ViT paper: [2010.11929] An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale I've reproduced...
Read more >Python Type Checking (Guide) - Real Python
The most common tool for doing type checking is Mypy though. ... If you try to run the reveal.py file as a Python...
Read more >Static type checking(with mypy): What's the official position?
Type annotation is half-there, half-not-there, mainly because the transformers library used to support python 2.7. For instance a new file like ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Although I hope mypy fixes the bug on their side, I did some digging into possible workarounds:
transformers
commit that causes mypy to crash is d8fb278, which makes sense. Adding apy.typed
enabled the type checking, which exposed the bug even though no code was changed in the commit itself. Any commit before it works without issues.transformers
type checked, add the following code tomypy.ini
:Hope this helps!
Just want to mention that the workaround for the newer pyproject.toml-based config files is