Issue 25581: Python -U raises error during site import (original) (raw)

process

Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, ezio.melotti, mrabarnett, paul.moore, ppperry, r.david.murray, serhiy.storchaka, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords:

Created on 2015-11-07 18:53 by ppperry, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg254293 - (view) Author: (ppperry) Date: 2015-11-07 18:53
C:\Documents and Settings\Perry>python -U Traceback (most recent call last): File "C:\Python27\lib\site.py", line 548, in main() File "C:\Python27\lib\site.py", line 537, in main aliasmbcs() File "C:\Python27\lib\site.py", line 465, in aliasmbcs import locale, codecs File "C:\Python27\lib\locale.py", line 182, in _percent_re = re.compile(r'%(?:\((?P.*?)\))?' File "C:\Python27\lib\re.py", line 194, in compile return _compile(pattern, flags) File "C:\Python27\lib\re.py", line 249, in _compile p = sre_compile.compile(pattern, flags) File "C:\Python27\lib\sre_compile.py", line 576, in compile code = _code(p, flags) File "C:\Python27\lib\sre_compile.py", line 561, in _code _compile(code, p.data, flags) File "C:\Python27\lib\sre_compile.py", line 151, in _compile _compile(code, av[1], flags) File "C:\Python27\lib\sre_compile.py", line 132, in _compile _compile(code, av[2], flags) File "C:\Python27\lib\sre_compile.py", line 107, in _compile _compile_charset(av, flags, code, fixup, fixes) File "C:\Python27\lib\sre_compile.py", line 232, in _compile_charset flags & SRE_FLAG_UNICODE): File "C:\Python27\lib\sre_compile.py", line 316, in _optimize_charset p = charmap.find(b'\1', q) TypeError: Type unicode doesn't support the buffer API
msg254319 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-11-08 02:10
Interesting, I didn't even know (remember?) about the -U flag, and it isn't documented. I guess we don't test it, and I suppose that it is effectively deprecated. (So others who don't remember don't need to repeat my research: it turns all string literals into unicode literals, which function was added as an experimental tool by Marc Andre in 2000. I believe it was later superseded by 'from __future__ import unicode_literals', but I didn't research that part.) This works fine on linux, and the traceback looks like it involves some windows-specific code. I'm not sure if this is worth bothering to fix.
msg254320 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2015-11-08 02:53
So, you write a string literal without a 'u' (or 'b') prefix, and there's no 'from __future__ import unicode_literals' in the module, so you expect it to be a bytestring, but it's not, it's a Unicode string. I'm not surprised that something breaks!
msg254323 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-11-08 05:50
Well, in this case *he* didn't write the string, it is embedded somewhere in the stdlib. 'python -U' gets you to the python prompt on unix, but apparently not on windows. But this isn't a feature we support any more, so I'm closing this as won't fix.
msg254324 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-08 05:53
What is worse, you write a string literal with a 'b' prefix, and you get a Unicode string. >>> b'' u'' I tried to use Python with -U (it could be good way to test compatibility with Python 3), but it is totally broken, and there is no hope to fix it.
msg254330 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-11-08 08:59
Reminder: use Python 3 to get an excellent Unicode support everywhere.
msg254331 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2015-11-08 09:13
> Interesting, I didn't even know (remember?) about the -U flag, and it isn't documented. https://docs.python.org/2/using/cmdline.html#cmdoption-U It isn't clear when this broken or why, but I think existing documentation could be adjusted to have a bigger warning around this option.
History
Date User Action Args
2022-04-11 14:58:23 admin set github: 69767
2015-11-08 09:13:08 SilentGhost set nosy: + SilentGhostmessages: +
2015-11-08 08:59:56 vstinner set messages: +
2015-11-08 05:53:46 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2015-11-08 05:50:09 r.david.murray set status: open -> closedresolution: wont fixmessages: + stage: resolved
2015-11-08 02:53:41 mrabarnett set messages: +
2015-11-08 02:10:23 r.david.murray set nosy: + r.david.murraymessages: +
2015-11-07 19:04:50 SilentGhost set nosy: + vstinnercomponents: + Unicode
2015-11-07 18:59:15 SilentGhost set nosy: + steve.dower, paul.moore, tim.golden, zach.warecomponents: + Windows, - Interpreter Core, Regular Expressions
2015-11-07 18:55:19 ppperry set title: Python -U fails with traceback -> Python -U raises error during site importnosy: + ezio.melotti, mrabarnettversions: + Python 2.7components: + Interpreter Core, Library (Lib), Regular Expressionstype: behavior
2015-11-07 18:53:50 ppperry create