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

Use 'as name' patter to re-export names from stubs (PEP 484) #1484

Merged
merged 4 commits into from
Jul 15, 2017

Conversation

ilevkivskyi
Copy link
Member

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

@gvanrossum
Copy link
Member

gvanrossum commented Jul 13, 2017

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
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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.

@JelleZijlstra JelleZijlstra merged commit d75ea88 into python:master Jul 15, 2017
@JelleZijlstra
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants