Skip to content

Commit

Permalink
closes bpo-37675: Use pkgutil.iter_modules to find fixers in a packag…
Browse files Browse the repository at this point in the history
…e rather than listdir. (14942)
  • Loading branch information
benjaminp authored Jul 24, 2019
1 parent 123536f commit 93e8aa6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Lib/lib2to3/refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Python imports
import io
import os
import pkgutil
import sys
import logging
import operator
Expand All @@ -30,13 +31,12 @@
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


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2to3 now works when run from a zipped standard library.

0 comments on commit 93e8aa6

Please sign in to comment.