Skip to content

Do not export imported names in stubs unless using 'as' #453

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
JukkaL opened this issue Sep 14, 2014 · 4 comments
Closed

Do not export imported names in stubs unless using 'as' #453

JukkaL opened this issue Sep 14, 2014 · 4 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 14, 2014

If a stub for module x imports something from typing, for example, currently from x import * also imports that name, which is wrong, since generally the module implementation does not import anything from typing, and besides it's just a bad idea in general.

However, we don't want to define __all__ for every stub, as that would be painful and redundant, since stubs mostly contain only exported features. Maybe we should not export any imported names by default, unless the import uses as. For example:

from typing import List    # Not exported
import os.path as path   # Exported
import os as os   # Also exported

This would only affect stubs. We need a way of knowing which files are stubs. Initially, just anything that is under stubs/ should be considered a stub.

@ambv
Copy link
Contributor

ambv commented Jan 8, 2015

Sorry, I disagree here. import os as os is unexpected. __all__ is verbose but at least people expect and understand it (hopefully?). Also, the fact that as was used is unavailable during runtime which might or might not be relevant in the future, for instance when somebody tries to implement runtime checks.

@gvanrossum
Copy link
Member

See my counter-proposal regarding __all__ in python/typing#22 (comment)

@JukkaL
Copy link
Collaborator Author

JukkaL commented May 17, 2015

We'll use the approach linked to in Guido's comment instead.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Aug 17, 2015

Update: We are back to using as: python/typing@4215e09

Also, now we can detect stubs easily as they use the .pyi extension, so this should be straightforward to implement.

@JukkaL JukkaL closed this as completed in 05c861b Oct 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants