Skip to content

Commit 531f66a

Browse files
gh-89885: Improve import example in language reference (GH-91523)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit d5a6957) Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
1 parent e5636f3 commit 531f66a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Doc/reference/import.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,21 +490,19 @@ submodule. Let's say you have the following directory structure::
490490
spam/
491491
__init__.py
492492
foo.py
493-
bar.py
494493

495-
and ``spam/__init__.py`` has the following lines in it::
494+
and ``spam/__init__.py`` has the following line in it::
496495

497496
from .foo import Foo
498-
from .bar import Bar
499497

500-
then executing the following puts a name binding to ``foo`` and ``bar`` in the
498+
then executing the following puts name bindings for ``foo`` and ``Foo`` in the
501499
``spam`` module::
502500

503501
>>> import spam
504502
>>> spam.foo
505503
<module 'spam.foo' from '/tmp/imports/spam/foo.py'>
506-
>>> spam.bar
507-
<module 'spam.bar' from '/tmp/imports/spam/bar.py'>
504+
>>> spam.Foo
505+
<class 'spam.foo.Foo'>
508506

509507
Given Python's familiar name binding rules this might seem surprising, but
510508
it's actually a fundamental feature of the import system. The invariant

0 commit comments

Comments
 (0)