Skip to content

Commit

Permalink
Monkeypatch imp.find_module into the native modulefinder._find_module.
Browse files Browse the repository at this point in the history
The modulefinder._find_module has an unpatched bug (python/cpython#84530) in py3.8, 3.9, 3.10.
Neither imp.find_module, nor the buggy modulefinder._find_module, handles namespace packages...

This fixes #130. #140, #141.
  • Loading branch information
thebjorn committed Apr 21, 2022
1 parent cae7383 commit 17a09ac
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pydeps/mf27.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

# from .mf.mf_next import * # for debugging next version
import modulefinder
from modulefinder import (
ModuleFinder as NativeModuleFinder
)
Expand All @@ -12,6 +13,12 @@

HAVE_ARGUMENT = dis.HAVE_ARGUMENT

# monkey-patch broken modulefinder._find_module
# (https://github.com/python/cpython/issues/84530)
# in Python 3.8-3.10
if hasattr(modulefinder, '_find_module'):
modulefinder._find_module = imp.find_module


class ModuleFinder(NativeModuleFinder):
def import_hook(self, name, caller=None, fromlist=None, level=-1):
Expand Down

0 comments on commit 17a09ac

Please sign in to comment.