aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2019-07-24 16:38:50 -0700
committerGitHub <noreply@github.com>2019-07-24 16:38:50 -0700
commit93e8aa62cfd0a61efed4a61a2ffc2283ae986ef2 (patch)
treebb4efcd33f41e41e7083f6ecb5190175a7c7324c /Lib/lib2to3
parentbpo-37672: Switch Windows Store package to use pip.ini for user mode (GH-14939) (diff)
downloadcpython-93e8aa62cfd0a61efed4a61a2ffc2283ae986ef2.tar.gz
cpython-93e8aa62cfd0a61efed4a61a2ffc2283ae986ef2.tar.bz2
cpython-93e8aa62cfd0a61efed4a61a2ffc2283ae986ef2.zip
closes bpo-37675: Use pkgutil.iter_modules to find fixers in a package rather than listdir. (14942)
Diffstat (limited to 'Lib/lib2to3')
-rw-r--r--Lib/lib2to3/refactor.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index 7841b99a5cd..55fd60fa27c 100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
@@ -14,6 +14,7 @@ __author__ = "Guido van Rossum <guido@python.org>"
# Python imports
import io
import os
+import pkgutil
import sys
import logging
import operator
@@ -30,13 +31,12 @@ from . import btm_matcher as bm
def get_all_fix_names(fixer_pkg, remove_prefix=True):
"""Return a sorted list of all available fix names in the given package."""
pkg = __import__(fixer_pkg, [], [], ["*"])
- fixer_dir = os.path.dirname(pkg.__file__)
fix_names = []
- for name in sorted(os.listdir(fixer_dir)):
- if name.startswith("fix_") and name.endswith(".py"):
+ for finder, name, ispkg in pkgutil.iter_modules(pkg.__path__):
+ if name.startswith("fix_"):
if remove_prefix:
name = name[4:]
- fix_names.append(name[:-3])
+ fix_names.append(name)
return fix_names