Skip to content

Commit

Permalink
Fix(ImportManager): Fix absolute import in Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
phdru committed Oct 23, 2024
1 parent 6abe5b5 commit 2c6cdac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cheetah/ImportManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def importHook(self, name, globals=None, locals=None,
# first see if we could be importing a relative name
_sys_modules_get = sys.modules.get
contexts = [None]
if globals:
if (PY2 or not name or level > 0) and globals:
importernm = globals.get('__name__', '')
if importernm:
if hasattr(_sys_modules_get(importernm), '__path__'):
Expand Down Expand Up @@ -477,7 +477,8 @@ def importHook(self, name, globals=None, locals=None,
if i < len(nmparts):
if ctx and hasattr(sys.modules[ctx], nmparts[i]):
return sys.modules[nmparts[0]]
del sys.modules[fqname]
if fqname in sys.modules:
del sys.modules[fqname]
raise ModuleNotFoundError("No module named %s" % fqname)
if fromlist is None:
if context:
Expand Down
2 changes: 2 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Bug fixes:
- Fixed ``ImportHooks``: it must raise ``ModuleNotFoundError``
instead of ``ImportError``.

- Fixed absolute import in ``ImportHooks`` under Python 3.

- Fixed ``Template.webInput``: Use ``urllib.parse.parse_qs``
instead of ``cgi.FieldStorage``; Python 3.13 dropped ``cgi``.

Expand Down

0 comments on commit 2c6cdac

Please sign in to comment.