-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Use 'as name' patter to re-export names from stubs (PEP 484) #1484
Use 'as name' patter to re-export names from stubs (PEP 484) #1484
Conversation
Please hold off on this until after the release of mypy 0.521 (or until Jukka vets it). |
stdlib/3.4/asyncio/futures.pyi
Outdated
@@ -1,5 +1,5 @@ | |||
import sys | |||
from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator, Awaitable | |||
from typing import Any, Union, Callable, TypeVar, List, Generic, Iterable, Generator, Awaitable as Awaitable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this here? Awaitable doesn't exist in this module at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it look like this is a bug at point of import in asyncio/locks.pyi
from . import filepost | ||
from . import poolmanager | ||
from . import response | ||
from . import filepost as filepost |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed? That feels like a bug in mypy or the PEP; child modules should always be re-exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of a corner case. PEP is very brief here saying just "everything that does not use as name
is hidden (except for import *
)". But probably this is indeed too verbose, I can special case this in mypy. Also probably some clarification in the PEP (with examples) is needed. Would you like making a PR to the python/peps
repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch. This is covered by a different notion, where submodules of packages are made available as attributes of their parent package as a side-effect of importing the submodule (implicitly or explicitly). So the 'as' idiom should not be needed here. But yeah, a PEP clarification would be good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I updated this PR and the mypy PR accordingly (the 'as name' rule does not apply to child modules now).
@@ -1,6 +1,6 @@ | |||
from typing import Any, Optional | |||
|
|||
from markupsafe import Markup, escape, soft_unicode | |||
from markupsafe import Markup as Markup, escape as escape, soft_unicode as soft_unicode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little strange (Jinja2 exports functions from markupsafe directly), but confirmed that it's correct.
Thanks! |
These were found with the help of python/mypy#3706
I am a bit worried that there might be more errors like these, but they are not caught, since some names are not imported (e.g. in top-level modules).
@JelleZijlstra please take a look. This should be merged (if OK) before python/mypy#3706