Skip to content

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

Closed

Description

@JukkaL

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.

Activity

  1. ambv commented on Jan 8, 2015

    @ambv
    Contributor

    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.

  2. gvanrossum commented on Jan 8, 2015

    @gvanrossum
    Member

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

  3. JukkaL commented on May 17, 2015

    @JukkaL
    CollaboratorAuthor

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

  4. JukkaL commented on Aug 17, 2015

    @JukkaL
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions