Skip to content

Commit 93e8aa6

Browse files
authored
closes bpo-37675: Use pkgutil.iter_modules to find fixers in a package rather than listdir. (14942)
1 parent 123536f commit 93e8aa6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Lib/lib2to3/refactor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# Python imports
1515
import io
1616
import os
17+
import pkgutil
1718
import sys
1819
import logging
1920
import operator
@@ -30,13 +31,12 @@
3031
def get_all_fix_names(fixer_pkg, remove_prefix=True):
3132
"""Return a sorted list of all available fix names in the given package."""
3233
pkg = __import__(fixer_pkg, [], [], ["*"])
33-
fixer_dir = os.path.dirname(pkg.__file__)
3434
fix_names = []
35-
for name in sorted(os.listdir(fixer_dir)):
36-
if name.startswith("fix_") and name.endswith(".py"):
35+
for finder, name, ispkg in pkgutil.iter_modules(pkg.__path__):
36+
if name.startswith("fix_"):
3737
if remove_prefix:
3838
name = name[4:]
39-
fix_names.append(name[:-3])
39+
fix_names.append(name)
4040
return fix_names
4141

4242

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2to3 now works when run from a zipped standard library.

0 commit comments

Comments
 (0)