Skip to content

Commit 544fa15

Browse files
uranusjrmiss-islington
authored andcommitted
Swap 'if' branches so content matches to condition in importlib example (GH-14947)
Prior to this change the guard on an 'elif' used an assignment expression whose value was used in a later 'else' block, causing some confusion for people. (Discussion on Twitter: https://twitter.com/brettsky/status/1153861041068994566.) Automerge-Triggered-By: @brettcannon
1 parent 898318b commit 544fa15

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Doc/library/importlib.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,14 +1640,14 @@ import, then you should use :func:`importlib.util.find_spec`.
16401640

16411641
if name in sys.modules:
16421642
print(f"{name!r} already in sys.modules")
1643-
elif (spec := importlib.util.find_spec(name)) is None:
1644-
print(f"can't find the {name!r} module")
1645-
else:
1643+
elif (spec := importlib.util.find_spec(name)) is not None:
16461644
# If you chose to perform the actual import ...
16471645
module = importlib.util.module_from_spec(spec)
16481646
sys.modules[name] = module
16491647
spec.loader.exec_module(module)
16501648
print(f"{name!r} has been imported")
1649+
else:
1650+
print(f"can't find the {name!r} module")
16511651

16521652

16531653
Importing a source file directly

0 commit comments

Comments
 (0)