New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid escape sequence DeprecationWarnings don't trigger by default #84380
Comments
The current warning filter seems to filter out the compile time DeprecationWarnings that get triggered on invalid escape sequences: import warnings
compile("'\d'", "<string>", "eval")
warnings.resetwarnings()
compile("'\d'", "<string>", "eval") results in one |
I get it printed two times. Actually I get it printed four times: two time when compile the test script (use r"'\d'" or "'\\d'" to get rid of them), and other two times when call compile() inside a script. $ ./python issue40199.py
issue40199.py:3: DeprecationWarning: invalid escape sequence \d
compile("'\d'", "<string>", "eval")
issue40199.py:5: DeprecationWarning: invalid escape sequence \d
compile("'\d'", "<string>", "eval")
<string>:1: DeprecationWarning: invalid escape sequence \d
<string>:1: DeprecationWarning: invalid escape sequence \d |
In what environment was that ran in? |
On Win 10, with recently compiled 3.7.7+ and 3.9.0a5+, I get 4 warnings also. >>> import warnings
>>> compile("'\d'", "<string>", "eval")
<stdin>:1: DeprecationWarning: invalid escape sequence \d
<string>:1: DeprecationWarning: invalid escape sequence \d
<code object <module> at 0x00A65DC0, file "<string>", line 1>
>>> warnings.resetwarnings()
>>> compile("'\d'", "<string>", "eval")
<stdin>:1: DeprecationWarning: invalid escape sequence \d
<string>:1: DeprecationWarning: invalid escape sequence \d
<code object <module> at 0x00A66190, file "<string>", line 1> Numerior, what 3.8 binaries are you running? I suspect that this should be closed as 'out of date'. |
The newest 64 bit release from python.org via the executable installer. |
OK, verified issue with installed 3.9.0a5, which must have different warning settings. From a file, 1 warning. Interactively, no warning. >>> compile("'\d'", "<string>", "eval")
<code object <module> at 0x00000263842DFC90, file "<string>", line 1>
>>> |
This is definitely not windows-specific. On macos: $ python3.9
Python 3.9.4 (default, Apr 5 2021, 01:47:16)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> '\s'
'\\s' |
Ah, there is a difference between debug and regular builds. I tested with the debug build. |
The cause of DeprecationWarning sometimes [1] not being issued is I believe because in string_parser.c [2] the module is explicitly set to NULL and the filename will be '<string>' or '<stdin>' or somesuch, which eventually that ends up being normalized to something that isn't '__main__'. Not sure if this is stating the obvious and I don't see any general solution short of adding a filter for the special filenames, but I caught wind of this in #python on Libera, got curious, and thought I'd share what I learned here. I've also attached a gdb session showing how changing the filename affects this behavior. Reproducing this in debug/dev contexts is definitely fraught, since the warning behavior is different. [1] The given compile() sample, at the REPL, when using -c, or when piping input via stdin are the ones I know about cpython/Parser/string_parser.c Lines 19 to 20 in f3fa63e
|
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: