-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
MyPy not acknowledging __all__ #1606
Comments
Thanks for the report! For whoever wants to tackle this, apparently mypy ignore the value of |
Was trying to tackle this. Given a |
The initializer is not accessible via |
You probably have to special-case assignment to `__all__`. ISTR that's how
type aliases are done.
|
How should messes like this be handled: from typing import List, Union
__all__ = None # type: Union[int, str, bytes, List[int], List[str]]
if True:
__all__ = 1
elif True:
__all__ = 'a'
elif True:
__all__ = [1]
elif True:
__all__ = ['a'] My guess is to make it an error if __all__ = 1 # ERROR: type of __all__ must be Sequence[str] and this would attempt to make if True:
__all__ = ['x']
else:
__all__ = ['y'] Any attempts to mutate it via |
Check the stdlib for patterns. IIRC asyncio has dynamic all. But yes, it should be Sequence of stress (or Any). --Guido (mobile) |
When MyPy encounters star (*) imports it considers every symbol defined in the given module as being imported even if an
__all__
attribute is present on the module.For example, say you have mypkg with two files, main.py:
and widget.py:
Running "mypy mypkg/app.py" issues the following error: "mypkg/app.py:2: error: Name 'datetime' already defined", though datetime should not be re-imported to the app module.
The text was updated successfully, but these errors were encountered: