-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Pylint incorrectly flags as unused-import
things that are used as variable type annotations
#1063
Comments
Yes, we do not currently process type comments. A planned support for PEP 484 is in our roadmap, but I am not sure how fast we will reach it. |
Partially fixed in #1231, but only if they are used as a sting annotations for function attributes. The full support is in question, as I don't personally see a way how to extract comments from AST(eroid) representation of the module... Any help or advice will be very appreciated. |
You can't extract comments from |
Hi. I built a pylint extension inspired by https://gist.github.com/PCManticore/eca887488248b7594d37 to handle precisely this for our code base. With it all the unused imports go away, and it'll even warn you of stuff you haven't imported. It also adds some inferences for special typing things like So if you think this is valuable I can work on cleaning up the code and making a pull request. I imagine this would be an extension that users can enable if they want to. Also suggestions on the name are welcome. Mine is called Cheers! |
@euresti That sounds pretty neat! Sure thing, please send a pull request. Depending on the additions, it might be something enabled by default. |
…as comments. For now let's call this an RFC don't merge as is. Basically this adds a plugin that adds a couple of transforms. the body as if they were real code. This silences unused-import and will trigger undefined-variable on missing imports. Since these lines get inserted in the same line as the happen multiple-statements is disable on those lines. creating new types by subscripting existing ones. intended to silence invalid-name. Also fixed a small bug in _supports_protocol where only metaclasses were looked at and not the metaclasses of the base classes. Tests pass! Fixes pylint-dev#1063
…as comments. For now let's call this an RFC don't merge as is. Basically this adds a plugin that adds a couple of transforms. the body as if they were real code. This silences unused-import and will trigger undefined-variable on missing imports. Since these lines get inserted in the same line as the happen multiple-statements is disable on those lines. creating new types by subscripting existing ones. intended to silence invalid-name. Also fixed a small bug in _supports_protocol where only metaclasses were looked at and not the metaclasses of the base classes. Tests pass! Fixes pylint-dev#1063
…as comments. For now let's call this an RFC don't merge as is. Basically this adds a plugin that adds a couple of transforms. the body as if they were real code. This silences unused-import and will trigger undefined-variable on missing imports. Since these lines get inserted in the same line as the happen multiple-statements is disable on those lines. creating new types by subscripting existing ones. intended to silence invalid-name. Also fixed a small bug in _supports_protocol where only metaclasses were looked at and not the metaclasses of the base classes. Tests pass! Fixes pylint-dev#1063
…as comments. For now let's call this an RFC don't merge as is. Basically this adds a plugin that adds a couple of transforms. the body as if they were real code. This silences unused-import and will trigger undefined-variable on missing imports. Since these lines get inserted in the same line as the happen multiple-statements is disable on those lines. creating new types by subscripting existing ones. intended to silence invalid-name. Also fixed a small bug in _supports_protocol where only metaclasses were looked at and not the metaclasses of the base classes. Tests pass! Fixes pylint-dev#1063
…as comments. For now let's call this an RFC don't merge as is. Basically this adds a plugin that adds a couple of transforms. the body as if they were real code. This silences unused-import and will trigger undefined-variable on missing imports. Since these lines get inserted in the same line as the happen multiple-statements is disable on those lines. creating new types by subscripting existing ones. intended to silence invalid-name. Also fixed a small bug in _supports_protocol where only metaclasses were looked at and not the metaclasses of the base classes. Tests pass! Fixes pylint-dev#1063
so what's the status with this? @euresti code did make it or not? |
It never made it in. My code is here: I don't use pylint anymore nor type comments anymore though. So I don't really have much need for this. Sorry. |
Pyflakes on python3 makes a vastly better experience IMO |
Certbot would love to see this! |
that would be very handy indeed! |
We recently switched to typed_ast from Dropbox, which has support for extracting type comments. This is fixed in the master branch, please give it a go when you get a chance! |
@PCManticore thanks, any non-dev release plans for it? 😄 |
Probably right after Python 3.7 comes out. We still have some issues to flesh out until then (check the 2.0 milestone from both pylint and astroid). |
Pylint knows nothing about types used in comments and raises false warnings about them [1]. A fix probably will not be released until Python 3.7. Currently, the only way to live with it is to supppress "unused import" warning. > gaborbernat commented on 24 May > @PCManticore thanks, any non-dev release plans for it? > > PCManticore commented on 24 May > Probably right after Python 3.7 comes out. We still have some issues > to flesh out until then (check the 2.0 milestone from both pylint and > astroid). [1]: pylint-dev/pylint#1063
@gaborbernat Already launched, forgot to reply. |
Are there any plans to also fix this for python 2? (pylint 1.9)? |
Steps to reproduce
Current behavior
pylint flags Optional as an unused-import
Expected behavior
pylint shouldn't flag Optional as unused-import
pylint --version output
pylint 1.6.4,
astroid 1.4.8
Python 3.5.2 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602]
Supporting documentation:
https://www.python.org/dev/peps/pep-0484/
The text was updated successfully, but these errors were encountered: