Skip to content

importlib.import_module() doesn't raise ModuleNotFoundError for non-existent modules in Python 3.11.4+. #108078

@felixxm

Description

@felixxm

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.11.4 (main, Jul 19 2023, 08:05:31) [GCC 11.3.0]

A clear and concise description of the bug:

# Python 3.11.4
# importlib.import_module() doesn't raise ModuleNotFoundError for non-existent modules.
>>> from importlib import import_module
>>> import_module("django.contrib.contenttypes.templatetags")
<module 'django.contrib.contenttypes.templatetags' from '/django/django/templatetags/__init__.py'>
# Python 3.10.9
>>> from importlib import import_module
>>> import_module("django.contrib.contenttypes.templatetags")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django.contrib.contenttypes.templatetags'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions