I am trying to silence mypy errors based on error codes. This is done using something like this:
from foolib import foo # type: ignore[attr-defined]
I believe PyCharm is interpreting my type: ignore[code]
comments as a type comment, and reporting ignore
as an unresolved reference.
Also, PyCharm expects an expression within the brackets.
mypy
error I'm trying to suppress:
pylint_ignore.py:8: error: Skipping analyzing 'pylint.utils': found module but no type hints or library stubs [import]
And yes, I know I can just say type: ignore
, and not include a code, or specify to ignore this particular import in a config file. However, I would like to specify the error codes, because I think it's a good feature.
How can I get PyCharm not to complain about this?
Research
This answer to How do I stop pyCharm from complaining about underscore strings?
Helped me realize under Preferences --> Editor --> Inspections --> Python --> Unresolved references
, I can add a fully qualified symbol name to be ignored.
I believe this is officially documented here.
I tried adding *.ignore.*
(since I don't want to have to build up a per-module ignore list), but this didn't work.
If this is the right approach, can you help me figure out the right syntax?
Versions
mypy==0.770
python==3.6.5
PyCharm PE 2020.1
To conclude, the unresolved reference error happens when Kotlin has no idea what the keyword you're typing in the file points to. It may be a function, a variable, or another construct of the language that you've yet to declare in the code.
Generally, this is a missing package problem, just place the caret at the unresolved reference and press Alt+Enter to reveal the options, then you should know how to solve it. Install via PyCharm (works with Community Edition).
I believe PyCharm is interpreting my type: ignore [code] comments as a type comment, and reporting ignore as an unresolved reference. Also, PyCharm expects an expression within the brackets. And yes, I know I can just say type: ignore, and not include a code, or specify to ignore this particular import in a config file.
To fix this: 1 Open PyCharm settings 2 Navigate to Editor -> File Types 3 Find Python and add __init__.py to the list of python files
Relative imports while code root folder is not the same as the project folder. Solution: Which is the most illusive of all the cases. Here, for some reason, PyCharm considers all __init__.py files not to be python files, and thus ignores them during code analysis. To fix this: Show activity on this post.
Apparently if you put a literal tab character between the #
and type:
, PyCharm will treat it as a regular comment. As PyCharm normally converts tab to spaces, you will have to copy it in from somewhere, but hey...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With