diff contrib/import-checker.py @ 52669:e627cc25b6f3

pyupgrade: rewrite `yield` statements in a loop to `yield from` This is the `legacy` fixer in `pyupgrade`, with the `yield` statement yielding loop commented back in. This seems to help pytype in some cases, and hurt it in others. But that can be manually fixed later. Note that it's possibly buggy in that it aggressively changed `import-checker.py` to `yield from 'fcntl', 'grp', 'pwd', 'select', 'termios': # Unix only`, which is invalid syntax. Possibly it needed help from the token fixer that I've disabled locally (because that wants to make a bunch of unrelated changes). Just change those few places to yield from a list, to avoid having to constantly revert that.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 05 Jan 2025 22:26:16 -0500
parents 0cc50d9ac6b0
children b95b12cb31e2
line wrap: on
line diff
--- a/contrib/import-checker.py	Sun Jan 05 22:23:31 2025 -0500
+++ b/contrib/import-checker.py	Sun Jan 05 22:26:16 2025 -0500
@@ -217,24 +217,19 @@
     >>> 'cffi' in mods
     True
     """
-    for m in sys.builtin_module_names:
-        yield m
+    yield from sys.builtin_module_names
     # These modules only exist on windows, but we should always
     # consider them stdlib.
-    for m in ['msvcrt', '_winreg']:
-        yield m
+    yield from ['msvcrt', '_winreg']
     yield '__builtin__'
     yield 'builtins'  # python3 only
     yield 'importlib.abc'  # python3 only
     yield 'importlib.machinery'  # python3 only
     yield 'importlib.util'  # python3 only
     yield 'packaging.version'
-    for m in 'fcntl', 'grp', 'pwd', 'select', 'termios':  # Unix only
-        yield m
-    for m in 'cPickle', 'datetime':  # in Python (not C) on PyPy
-        yield m
-    for m in ['cffi']:
-        yield m
+    yield from ['fcntl', 'grp', 'pwd', 'select', 'termios']
+    yield from ['cPickle', 'datetime']
+    yield from ['cffi']
     yield 'distutils'  # in Python < 3.12
     yield 'distutils.version'  # in Python < 3.12
     stdlib_prefixes = {sys.prefix, sys.exec_prefix}
@@ -443,10 +438,9 @@
 
         if newscope:
             # Check for local imports in function
-            for r in verify_modern_convention(
+            yield from verify_modern_convention(
                 module, node, localmods, node.col_offset + 4
-            ):
-                yield r
+            )
         elif isinstance(node, ast.Import):
             # Disallow "import foo, bar" and require separate imports
             # for each module.