[Python-checkins] Swap 'if' branches so content matches to condition in importlib example (GH-14947)

Miss Islington (bot) webhook-mailer at python.org
Thu Jul 25 13:28:05 EDT 2019


https://github.com/python/cpython/commit/c594c274e92dc66afad02fe7a3c08a9b6c5a396d
commit: c594c274e92dc66afad02fe7a3c08a9b6c5a396d
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-07-25T10:27:59-07:00
summary:

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
(cherry picked from commit 544fa15ea1b7b73068319bdb217b684e2fd7bacc)

Co-authored-by: Tzu-ping Chung <uranusjr at gmail.com>

files:
M Doc/library/importlib.rst

diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index 9fab0779aa74..65a685022e92 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -1640,14 +1640,14 @@ import, then you should use :func:`importlib.util.find_spec`.
 
   if name in sys.modules:
       print(f"{name!r} already in sys.modules")
-  elif (spec := importlib.util.find_spec(name)) is None:
-      print(f"can't find the {name!r} module")
-  else:
+  elif (spec := importlib.util.find_spec(name)) is not None:
       # If you chose to perform the actual import ...
       module = importlib.util.module_from_spec(spec)
       sys.modules[name] = module
       spec.loader.exec_module(module)
       print(f"{name!r} has been imported")
+  else:
+      print(f"can't find the {name!r} module")
 
 
 Importing a source file directly



More information about the Python-checkins mailing list