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

False positive "unused-import" for typing python 3.7.4 #3193

Closed
davidgiga1993 opened this issue Oct 16, 2019 · 6 comments
Closed

False positive "unused-import" for typing python 3.7.4 #3193

davidgiga1993 opened this issue Oct 16, 2019 · 6 comments
Labels
Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine

Comments

@davidgiga1993
Copy link

davidgiga1993 commented Oct 16, 2019

python 3.7.4 on linux:

from typing import Optional

class A:
    def __init__(self):
        self.field = None  # type: Optional[str]
pylint  Test.py
************* Module Test
...
Test.py:1:0: W0611: Unused Optional imported from typing (unused-import)

pylint --version
pylint 2.4.2
astroid 2.3.1
Python 3.7.4 (default, Jul 23 2019, 10:08:33)
[GCC 4.8.5]

Interestingly I don't get this issue on windows with python 3.7.3 or 3.7.4:

pylint --version
pylint 2.4.2
astroid 2.3.1
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)]

Any ideas what could cause this issue?

@davidgiga1993 davidgiga1993 changed the title False positive "unused-import" for typing on linux False positive "unused-import" for typing python 3.7.4 Oct 16, 2019
@PCManticore
Copy link
Contributor

Can you check if you have typed-ast installed?

@PCManticore PCManticore added the Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine label Oct 16, 2019
@davidgiga1993
Copy link
Author

davidgiga1993 commented Oct 16, 2019

Yes typed_ast is installed on both systems in V1.4.0.
I also tried Python3.7.4 on windows and it's working fine

@saf
Copy link

saf commented Oct 17, 2019

Isn't this a duplicate of #3191, or at least the same root cause?

@davidgiga1993
Copy link
Author

Could be yes. Although it would raise the question why it's working on windows but not on linux

@PCManticore
Copy link
Contributor

@davidgiga1993 I can't reproduce this issue on my computer with typed-ast==1.4.0 and

pylint 2.4.3
astroid 2.3.3
Python 3.7.0 (default, Jul  4 2018, 10:51:54)
[Clang 8.1.0 (clang-802.0.42)]

I'm not sure what the culprit might be given you already have typed-ast installed. As a last resort, you can do a breakpoint in leave_assign in pylint/checkers/variables.py and check if the node that is received for that method has a type_annotation attribute properly set. If it has, there might be a bug somewhere else down the line, but if not, it most likely is an issue with typed-ast itself.
Sorry I can't be of more help but cannot currently reproduce it.

@rpdelaney
Copy link

rpdelaney commented Nov 14, 2019

I came here to report this issue that I observed in a module using weakref. Since it's built-in, hopefully this repro will work for you:

from typing import Optional
import weakref


class foo:
    def __init__(self, thing):
        self.bar = thing  # type:Optional[weakref.ref[int]]
$ pip3 freeze | grep typed-ast
typed-ast==1.4.0
$ pylint --version
pylint 2.4.3
astroid 2.3.3
Python 3.7.4 (default, Oct  4 2019, 06:57:26) 
[GCC 9.2.0]
$ pylint foo.py
************* Module foo
foo.py:2:0: W0611: Unused import weakref (unused-import)

------------------------------------------------------------------
Your code has been rated at 8.00/10 (previous run: 8.00/10, +0.00)

Edit: If it would help, I may be able to provide a tarball of a virtualenv with a repro in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine
Projects
None yet
Development

No branches or pull requests

4 participants