You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
python -m inspect --details fails in nondecodable directory #69370
$ 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_codeexec(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 _mainprint('Origin: {}'.format(getsourcefile(module)))
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 27: surrogates not allowed
./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).
Activity
serhiy-storchaka commentedon Sep 19, 2015
dignissimus commentedon Apr 23, 2022
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.
vstinner commentedon Sep 22, 2023
./python -m inspectcan 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 commentedon Sep 22, 2023
Does it work to just add:
sys.stdout.reconfigure(errors="backslashreplace")?gh-69370: Fix "python -m inspect --details" for unencodable paths (GH…
[3.13] gh-69370: Fix "python -m inspect --details" for unencodable pa…
[3.14] gh-69370: Fix "python -m inspect --details" for unencodable pa…
pythongh-69370: Fix "python -m inspect --details" for unencodable pat…
[3.15] gh-69370: Fix "python -m inspect --details" for unencodable pa…