Repository navigation
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). |
| @@ -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.
Why is this here? Awaitable doesn't exist in this module at runtime.
There was a problem hiding this comment.
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.
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.
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.
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.
OK, I updated this PR and the mypy PR accordingly (the 'as name' rule does not apply to child modules now).
| 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.
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