Skip to content

Commit 53639dd

Browse files
closes bpo-37675: Use pkgutil.iter_modules to find fixers in a package rather than listdir. (14942)
(cherry picked from commit 93e8aa6) Co-authored-by: Benjamin Peterson <[email protected]>
1 parent 46c2eff commit 53639dd

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
@@ -15,6 +15,7 @@
1515

1616
# Python imports
1717
import os
18+
import pkgutil
1819
import sys
1920
import logging
2021
import operator
@@ -33,13 +34,12 @@
3334
def get_all_fix_names(fixer_pkg, remove_prefix=True):
3435
"""Return a sorted list of all available fix names in the given package."""
3536
pkg = __import__(fixer_pkg, [], [], ["*"])
36-
fixer_dir = os.path.dirname(pkg.__file__)
3737
fix_names = []
38-
for name in sorted(os.listdir(fixer_dir)):
39-
if name.startswith("fix_") and name.endswith(".py"):
38+
for finder, name, ispkg in pkgutil.iter_modules(pkg.__path__):
39+
if name.startswith("fix_"):
4040
if remove_prefix:
4141
name = name[4:]
42-
fix_names.append(name[:-3])
42+
fix_names.append(name)
4343
return fix_names
4444

4545

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)