File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -512,6 +512,22 @@ code::
512
512
This would mean that ``from sound.effects import * `` would import the three
513
513
named submodules of the :mod: `sound.effects ` package.
514
514
515
+ Be aware that submodules might become shadowed by locally defined names. For
516
+ example, if you added a ``reverse `` function to the
517
+ :file: `sound/effects/__init__.py ` file, the ``from sound.effects import * ``
518
+ would only import the two submodules ``echo `` and ``surround ``, but *not * the
519
+ ``reverse `` submodule, because it is shadowed by the locally defined
520
+ ``reverse `` function::
521
+
522
+ __all__ = [
523
+ "echo", # refers to the 'echo.py' file
524
+ "surround", # refers to the 'surround.py' file
525
+ "reverse", # !!! refers to the 'reverse' function now !!!
526
+ ]
527
+
528
+ def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule
529
+ return msg[::-1] # in the case of a 'from sound.effects import *'
530
+
515
531
If ``__all__ `` is not defined, the statement ``from sound.effects import * ``
516
532
does *not * import all submodules from the package :mod: `sound.effects ` into the
517
533
current namespace; it only ensures that the package :mod: `sound.effects ` has
You can’t perform that action at this time.
0 commit comments