Skip to content

Invalid undefined variable errors (mypy not considering __all__?) #451

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

Closed
refi64 opened this issue Sep 13, 2014 · 4 comments
Closed

Invalid undefined variable errors (mypy not considering __all__?) #451

refi64 opened this issue Sep 13, 2014 · 4 comments
Labels
bug mypy got something wrong

Comments

@refi64
Copy link
Contributor

refi64 commented Sep 13, 2014

Sample:

from abc import abstractmethod
from typing import *

T = typevar('T')

class Rnd(Protocol[T]):
    @abstractmethod
    def some_method(x: T) -> T:
        pass

That gives:

err.py, line 2: Name 'T' already defined
err.py, line 2: Name 'abstractmethod' already defined
err.py, line 6: Name 'Protocol' is not defined

Removing the top line solves the second error, but it obviously doesn't run under Python 3:

Traceback (most recent call last):
  File "err.py", line 6, in <module>
    class Rnd(Protocol[T]):
  File "err.py", line 7, in Rnd
    @abstractmethod
NameError: name 'abstractmethod' is not defined
@refi64 refi64 changed the title Invalid undefined check errors (mypy not considering __all__?) Invalid undefined variable errors (mypy not considering __all__?) Sep 13, 2014
@JukkaL
Copy link
Collaborator

JukkaL commented Sep 14, 2014

Yup, __all__ is not yet supported :(

It should be pretty easy to implement, at least for simple cases which don't mutate __all__ after initialization.

Also, the stubs for typing should use _T etc. for internal identifiers (and other stubs as well). The problem withabstractmethod etc. could be worked around by using from abc import abstractmethod as _abstractmethod, I think. This is probably the easiest way to enable from typing import *.

Another issue is that importing the same name from multiple modules (e.g., directly from abc and via from foo import *) should not be fine.

(Note also that Protocol and structural subtyping is not supported by the type checker, but it's pretty likely that it will be added in the future.)

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 14, 2014

Added issue #452 for the issue with T.

@JukkaL JukkaL added the bug mypy got something wrong label Sep 14, 2014
@JukkaL
Copy link
Collaborator

JukkaL commented Sep 14, 2014

Added issue #453 as a general fix to the problem with imports in stubs.

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 24, 2014

Bumping priority because this is pretty annoying.

@ddfisher ddfisher added this to the Future milestone Mar 2, 2016
@gnprice gnprice removed the priority label Mar 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

5 participants