Opened 14 years ago

Closed 14 years ago

Last modified 8 years ago

#15662 closed Bug (fixed)

module_has_submodule incorrectly uses the Importer Protocol

Reported by: Bradley Ayers <bradley.ayers@…> Owned by: nobody
Component: Core (Other) Version: 1.2
Severity: Normal Keywords:
Cc: lrekucki@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.utils.module_loading.module_has_submodule has the code:

for finder in sys.meta_path:
    if finder.find_module(name):
        return True

where name is the absolute path to the module that should be imported. However PEP302 that defines the Importer Protocol says that a second argument must be supplied if the module isn't directly on sys.path.

Thus, the code should be:

for finder in sys.meta_path:
    if finder.find_module(name, package):
        return True

I came across this problem with using Attest, Django, and loading a template tag that had the same name as a package on my PATH.

Attachments (3)

module_loading.py.patch (491 bytes ) - added by Bradley Ayers <bradley.ayers@…> 14 years ago.
module_loading.py.2.patch (492 bytes ) - added by Bradley Ayers <bradley.ayers@…> 14 years ago.
Fixed typo
module_has_submodule.patch (2.7 KB ) - added by Bradley Ayers <bradley.ayers@…> 14 years ago.
Added tests

Download all attachments as: .zip

Change History (11)

by Bradley Ayers <bradley.ayers@…>, 14 years ago

Attachment: module_loading.py.patch added

comment:1 by Łukasz Rekucki, 14 years ago

Cc: lrekucki@… added

comment:2 by Alex Gaynor, 14 years ago

a) There's a typo in the patch, b) could use tests, c) <redacted> :)

by Bradley Ayers <bradley.ayers@…>, 14 years ago

Attachment: module_loading.py.2.patch added

Fixed typo

by Bradley Ayers <bradley.ayers@…>, 14 years ago

Attachment: module_has_submodule.patch added

Added tests

comment:3 by Bradley Ayers <bradley.ayers@…>, 14 years ago

Component: UncategorizedCore framework

comment:4 by Luke Plant, 14 years ago

Type: Bug

comment:5 by Luke Plant, 14 years ago

Severity: Normal

comment:6 by Luke Plant, 14 years ago

milestone: 1.3
Triage Stage: UnreviewedReady for checkin

comment:7 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

In [16075]:

Fixed #15662 -- Made sure the module_has_submodule utility function follow correct PEP 302, passing the package as the second argument to the find_module method of the importer. Thanks, Bradley Ayers.

comment:8 by GitHub <noreply@…>, 8 years ago

In 9e9e7373:

Refs #23919 -- Removed an obsolete test for a Python 2 code path (refs #15662).

Fixed #21628 by removing the last usage of the imp module.

Note: See TracTickets for help on using tickets.
Back to Top