Skip to content

gh-134280: Disable constant folding for ~ with a boolean argument #134982

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented May 31, 2025

This moves the deprecation warning from compile time to runtime.

This moves the deprecation warning from compile time to runtime.
@serhiy-storchaka
Copy link
Member Author

3.14 and 3.13 differ from main, so I would do backporting step by step.

@iritkatriel
Copy link
Member

If we can detect this in https://github.com/python/cpython/blob/main/Python/ast_preprocess.c then we get the warning in both static analysis and execution.

@serhiy-storchaka
Copy link
Member Author

Yes, but we only add SyntaxWarning for very common errors. ~True is unlikely used in real code.

@iritkatriel
Copy link
Member

Is it hard to detect this in the preprocessor?

@serhiy-storchaka
Copy link
Member Author

I do not know. But even a couple lines of code is a high price for this feature. And it will be more than a couple lines.

Comment on lines +1895 to +1897
if (PyBool_Check(operand)) { // ~bool is deprecated
return NULL;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to add a comment that this should be removed once the ~bool depreciation expires? When it raises in the future, raising at compile time is equally good if not better and it makes the code slightly simpler by removing the special casing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants