python / cpython

The Python programming language
https://www.python.org
Other
63.39k stars 30.36k forks source link

python -m inspect --details fails in nondecodable directory #69370

Open serhiy-storchaka opened 9 years ago

serhiy-storchaka commented 9 years ago
BPO 25183
Nosy @serhiy-storchaka, @1st1

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['type-bug', 'library'] title = 'python -m inspect --details fails in nondecodable directory' updated_at = user = 'https://github.com/serhiy-storchaka' ``` bugs.python.org fields: ```python activity = actor = 'Arfrever' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'serhiy.storchaka' dependencies = [] files = [] hgrepos = [] issue_num = 25183 keywords = [] message_count = 1.0 messages = ['251116'] nosy_count = 3.0 nosy_names = ['Arfrever', 'serhiy.storchaka', 'yselivanov'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue25183' versions = ['Python 3.4', 'Python 3.5', 'Python 3.6'] ```

serhiy-storchaka commented 9 years ago
$ pwd
/home/serhiy/py/cpy�thon-3.5
$ ./python -m inspect --details unittest
Target: unittest
Traceback (most recent call last):
  File "/home/serhiy/py/cpy\udcffthon-3.5/Lib/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/serhiy/py/cpy\udcffthon-3.5/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/serhiy/py/cpy\udcffthon-3.5/Lib/inspect.py", line 3050, in <module>
    _main()
  File "/home/serhiy/py/cpy\udcffthon-3.5/Lib/inspect.py", line 3030, in _main
    print('Origin: {}'.format(getsourcefile(module)))
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 27: surrogates not allowed
dignissimus commented 2 years ago

On Python 3.11 when creating a directory containing \udcff I receive the following error that happens even when I'm not running the inspect module.

sam@samtop /tmp/bpo/python\M-^?-3.11 (git)-[main] % ./python
Exception ignored error evaluating path:
Traceback (most recent call last):
  File "<frozen getpath>", line 348, in <module>
ModuleNotFoundError: No module named 'encodings'
Fatal Python error: error evaluating path
Python runtime state: core initialized

Current thread 0x00007f6594655740 (most recent call first):
  <no Python frame>
1 sam@samtop /tmp/bpo/python\M-^?-3.11 (git)-[main] % 
vstinner commented 1 year ago

./python -m inspect can maybe reconfigure sys.stdout to use a different error handler than strict? Like backslashreplace or replace. I don't think that it's worth it to add special code just to display "Origin: ", many other strings can contain characters not encoding to stdout encoding (UTF-8 in your case).

vstinner commented 1 year ago

Does it work to just add: sys.stdout.reconfigure(errors="backslashreplace")?