classification
Title: Unbounded recursion in modulefinder
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: jvr, mhammond, theller
Priority: normal Keywords:

Created on 2004-01-13 18:46 by theller, last changed 2004-05-11 15:12 by theller. This issue is now closed.

Files
File name Uploaded Description Edit
modulefinder.patch theller, 2004-03-30 19:10 Patch againt release23-maint branch
Messages (8)
msg19667 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-01-13 18:46
modulefinder goes into unbounded recursion when a
module named 'path.py', containing 'import os', is on
sys.path.

Last part of the traceback:
  File "c:\python23\lib\modulefinder.py", line 255, in
import_module
    m = self.load_module(fqname, fp, pathname, stuff)
  File "c:\python23\lib\modulefinder.py", line 285, in
load_module
    self.scan_code(co, m)
  File "c:\python23\lib\modulefinder.py", line 342, in
scan_code
    self._safe_import_hook(name, m, fromlist)
  File "c:\python23\lib\modulefinder.py", line 300, in
_safe_import_hook
    self.import_hook(name, caller)
  File "c:\python23\lib\modulefinder.py", line 124, in
import_hook
    q, tail = self.find_head_package(parent, name)
  File "c:\python23\lib\modulefinder.py", line 166, in
find_head_package
    q = self.import_module(head, qname, parent)
  File "c:\python23\lib\modulefinder.py", line 237, in
import_module
    self.msgin(3, "import_module", partname, fqname,
parent)
RuntimeError: maximum recursion depth exceeded

Running modulefinder with the '-x os.path' command line
option prevents the recursion.

This is not really a contrived situation, there's a
possibly useful path.py module from Jason Orendorff at
<http://www.jorendorff.com/articles/python/path>
msg19668 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-01-28 20:36
Logged In: YES 
user_id=11105

Just, do you have time to look into this?
msg19669 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-03-25 20:06
Logged In: YES 
user_id=11105

<ping> Just, do you have time to look into this?
msg19670 - (view) Author: Just van Rossum (jvr) * Date: 2004-03-25 20:53
Logged In: YES 
user_id=92689

Hm, not really. Do you have any idea what's causing it?
msg19671 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-03-25 21:09
Logged In: YES 
user_id=11105

It has something to do with os.path.  Adding 'os.path' to
the excludes list, the problem does not appear.

Adding print statements it seems that mf is looking for 
os.os.os.os.os.......something, it seems that it recurses
without noting that something failed.

If I had to fix this myself, I probably had to first step
through these imports with the C debugger, and then through mf.
msg19672 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-03-30 19:10
Logged In: YES 
user_id=11105

I think I have found something, but I still have to check if
this cures the original problem.

Imagine an (possibly empty) module foo.py.  Without this
patch, modulefinder would even find 'import foo.foo.foo'
modules.

The assert in the second hunk is commented out, although I
think it should be correct.

Just, any comments?
msg19673 - (view) Author: Mark Hammond (mhammond) * (Python committer) Date: 2004-04-28 07:11
Logged In: YES 
user_id=14198

the patch looks reasonable to me, and I can demonstrate that
it does fix the original problem as described.
msg19674 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-05-11 15:12
Logged In: YES 
user_id=11105

Thanks, Mark.
Checked in as Lib/modulefinder.py CVS revision 1.7.6.2 and 1.11.
History
Date User Action Args
2004-01-13 18:46:43thellercreate