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.

Author SnoopJeDi
Recipients Numerlor, SnoopJeDi, habnabit, ncoghlan, serhiy.storchaka, terry.reedy, vstinner
Date 2021-06-03.18:25:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1622744746.76.0.702609732096.issue40199@roundup.psfhosted.org>
In-reply-to
Content
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
[2] https://github.com/python/cpython/blob/f3fa63ec75fdbb4a08a10957a5c631bf0c4a5970/Parser/string_parser.c#L19-L20
History
Date User Action Args
2021-06-03 18:25:46SnoopJeDisetrecipients: + SnoopJeDi, terry.reedy, ncoghlan, vstinner, habnabit, serhiy.storchaka, Numerlor
2021-06-03 18:25:46SnoopJeDisetmessageid: <1622744746.76.0.702609732096.issue40199@roundup.psfhosted.org>
2021-06-03 18:25:46SnoopJeDilinkissue40199 messages
2021-06-03 18:25:46SnoopJeDicreate