This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: infinite recursion with setfilesystemencoding and pdb
Type: behavior Stage: resolved
Components: None Versions: Python 3.1
Status: closed Resolution: duplicate
Dependencies: Superseder: sys.setfilesystemencoding("xxx"); open("a") => stack overflow
View: 8226
Assigned To: Nosy List: ccomb, flox, vstinner
Priority: normal Keywords:

Created on 2010-05-17 13:45 by ccomb, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg105904 - (view) Author: Christophe Combelles (ccomb) Date: 2010-05-17 13:45
This leads to a maximum recursion depth error:

$ python3.1
>>> import sys, pdb
>>> sys.setfilesystemencoding('iso8859-7')
>>> pdb.set_trace()

I'm on ubuntu 10.04 x86_64, with LANG=fr_FR.utf8
msg105906 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-05-17 15:05
Next release should fix it: 3.1.3
(Tested on 3.1 branch)
msg105910 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-05-17 15:13
What is the problem?

$ python3.1
Python 3.1.2 (r312:79147, Apr 21 2010, 23:52:07) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, pdb; sys.setfilesystemencoding('iso8859-7'); pdb.set_trace()
> <stdin>(1)<module>()->None

Where is the infinite loop?
msg105911 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-05-17 15:18
The file system encoding should not be modifiable. Call sys.setfilesystemencoding() breaks Python, eg. module filenames are not reencoded. See also #8611.

sys.setfilesystemencoding() is as danregeous as sys.setdefaultencoding() because it changes too much things in Python.

If you would like to decode a filename with an encoding different than sys.setfilesystemencoding(): use the bytes type. Eg. os.listdir(b'.') gives you bytes filenames.
msg105912 - (view) Author: Christophe Combelles (ccomb) Date: 2010-05-17 15:19
Traceback (most recent call last):
  File "/usr/lib/python3.1/encodings/", line 98, in search_function
  File "/usr/lib/python3.1/encodings/", line 98, in search_function
  File "/usr/lib/python3.1/encodings/", line 98, in search_function
  File "/usr/lib/python3.1/encodings/", line 98, in search_function
  File "/usr/lib/python3.1/encodings/", line 83, in search_function
    norm_encoding = normalize_encoding(encoding)
  File "/usr/lib/python3.1/encodings/", line 55, in normalize_encoding
    if isinstance(encoding, bytes):
RuntimeError: maximum recursion depth exceeded while calling a Python object
msg105913 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-05-17 15:23
Oh, flox closed the issue: it's a duplicate of #8226. The bug was fixed in Python 3.1.2 by myself (r79394).
msg106050 - (view) Author: Christophe Combelles (ccomb) Date: 2010-05-19 12:03
(I forgot to mention that the bug occured on python 3.1.2.)
Date User Action Args
2022-04-11 14:57:01adminsetgithub: 52986
2010-05-19 12:03:22ccombsetmessages: + msg106050
2010-05-17 15:23:20vstinnersetmessages: + msg105913
2010-05-17 15:19:41ccombsetmessages: + msg105912
2010-05-17 15:18:34vstinnersetmessages: + msg105911
2010-05-17 15:13:02vstinnersetmessages: + msg105910
2010-05-17 15:05:04floxsetstatus: open -> closed

superseder: sys.setfilesystemencoding("xxx"); open("a") => stack overflow

nosy: + vstinner, flox
messages: + msg105906
resolution: duplicate
stage: resolved
2010-05-17 13:45:49ccombcreate