Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue6504] infinite recursion from calling builtins.open()

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jul 17, 2009, 8:36 AM

Post #1 of 5 (264 views)
Permalink
[issue6504] infinite recursion from calling builtins.open()

New submission from kai zhu <kaizhu256 [at] gmail>:

# copy this to test.py
# > touch foo.txt
# > python3.1 -c "import test; import collections"
# > ...
# > File "test.py", line 5, in find_module
# > def find_module(self, mname, path = None): open("foo.txt")
# > File "test.py", line 5, in find_module
# > def find_module(self, mname, path = None): open("foo.txt")
# > File "test.py", line 5, in find_module
# > def find_module(self, mname, path = None): open("foo.txt")
# > File "test.py", line 5, in find_module
# > def find_module(self, mname, path = None): open("foo.txt")
# > RuntimeError: maximum recursion depth exceeded while calling a
# > Python object
class importer(object):
def find_module(self, mname, path = None): open("foo.txt")
import sys; sys.meta_path.append(importer)

***

# note recursion behavior stops if we don't call open()
class importer(object):
def find_module(self, mname, path = None): pass
import sys; sys.meta_path.append(importer)

----------
components: IO, Interpreter Core
messages: 90627
nosy: kaizhu
severity: normal
status: open
title: infinite recursion from calling builtins.open()
type: behavior
versions: Python 3.1

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6504>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 17, 2009, 4:12 PM

Post #2 of 5 (237 views)
Permalink
[issue6504] infinite recursion from calling builtins.open() [In reply to]

kai zhu <kaizhu256 [at] gmail> added the comment:

recursion also goes away if we open as raw bytes: open("foo.txt", "rb"). modes "r+" & "w" also give infinite recursion, while "rb+" & "wb" do not.

note found another bug:
instance method find_module should raise exception anyway, since its
class was uninstantiated in sys.meta_path (proper behavior in python2.6)

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6504>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 18, 2009, 3:17 AM

Post #3 of 5 (240 views)
Permalink
[issue6504] infinite recursion from calling builtins.open() [In reply to]

Georg Brandl <georg [at] python> added the comment:

First, the second bug isn't a bug since that restriction has been lifted
in Python 3.

The original issue occurs because open() for text modes imports the
"locale" module. This is kind of nasty, because calling open() is well
within what a find_module() implementation should be able to do. Antoine?

----------
assignee: -> pitrou
nosy: +georg.brandl, pitrou

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6504>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 18, 2009, 3:48 AM

Post #4 of 5 (235 views)
Permalink
[issue6504] infinite recursion from calling builtins.open() [In reply to]

kai zhu <kaizhu256 [at] gmail> added the comment:

current hack-around, then is to pre-import locale, which is verified to
work:

# beg test.py
class importer(object):
def find_module(self, mname, path = None): open("foo.txt")
import sys, locale; sys.meta_path.append(importer)
import collections # no recursion
# end test.py

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6504>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 19, 2009, 3:23 AM

Post #5 of 5 (225 views)
Permalink
[issue6504] infinite recursion from calling builtins.open() [In reply to]

Antoine Pitrou <pitrou [at] free> added the comment:

Yes, we conditionally import the "locale" module in order to guess the
encoding when it is not specified by the caller. We can't import it at
module initialization time because it would cause bootstrapping issues.

The Python equivalent of the logic expressed in C code in the _io module
can be found here:
http://code.python.org/hg/branches/py3k/file/51117227ac82/Lib/_pyio.py#l1410

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6504>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.