Skip to content

Commit

Permalink
PEP 484: Clarify that submodules in a package are exported
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Jul 15, 2017
1 parent ea76e44 commit 51a178b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pep-0484.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,10 @@ Additional notes on stub files:
* However, as an exception to the previous bullet, all objects
imported into a stub using ``from ... import *`` are considered
exported. (This makes it easier to re-export all objects from a
given module that may vary by Python version.)
given module that may vary by Python version.) Similarly, imports
of submodules in the ``__init__.pyi`` files of a package are
considered exported. For example, if ``a/__init__.pyi`` contains
just ``from . import b``, then ``b`` is exported.

This comment has been minimized.

Copy link
@gvanrossum

gvanrossum Jul 16, 2017

This is slightly misleading, because it suggests the mechanism may depend on the name b in the package namespace. The actual mechanism is that all imported submodules of a package appear as exported attributes of the package. So even if a/__init__.pyi contained this:

class C:
    import a.b

then b would become an attribute of a. (There's code in the runtime to do this, and a type checker ought to emulate the runtime behavior here.)

(FWIW I wouldn't use that example in the PEP text, this is just to explain it to you so you may come up with a reasonable edit to the PEP text.)

This comment has been minimized.

Copy link
@gvanrossum

gvanrossum Jul 16, 2017

(Oh, there's also some exception on this exception if a/__init__.pyi contains something like b = 42 -- then that is supposed to win.)

This comment has been minimized.

Copy link
@JelleZijlstra

JelleZijlstra Jul 17, 2017

Author Owner

Thanks for the explanation! I think I'll add a reference to the relevant documentation in https://docs.python.org/3/reference/import.html#submodules.


* Stub files may be incomplete. To make type checkers aware of this, the file
can contain the following code::
Expand Down

0 comments on commit 51a178b

Please sign in to comment.