-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-115419: Change default sym to not_null #116562
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
gh-115419: Change default sym to not_null #116562
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, no time to review yet, but a suggestion for the test.
Lib/test/test_capi/test_opt.py
Outdated
"""Note: this function must be executed in a subprocess, because when other tests are run, | ||
the globals of this module might get affected, causing globals to constant promotion | ||
to fail. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I betcha you can do without a subprocess. Instead, just create a namespace and use that, like several other tests do. The namespace directory acts as the globals for the function defined in it. Try it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry my Python is actually somewhat rusty -- which namespace are you referring to? I don't remember types.SimpleNamespace
being that powerful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a dict -- look at test_type_inconsistency()
in the same file for a complete example. Because it says exec(src, ns, ns)
the ns
dict is used as the globals for the function, and you can add/update its "globals" using ns["some_name"] = some_value
.
There are two parts to this, AFAICT.
1 seems like a worthwhile change, but 2 is incorrect as functions are mutable. Could you move 1 to its own PR? |
FWIW This may be off-topic and a pipe dream, but I have a feeling that we ought to consider deprecating certain rare mutable attributes. E.g. assignments to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure how to go about making sure that we didn't miss any opcodes that might push NULL
. I checked for ones with NULL
in their name, and they're all covered. How did you even find _LOAD_ATTR
?
(void)owner; | ||
OUT_OF_SPACE_IF_NULL(attr = sym_new_not_null(ctx)); | ||
if (oparg & 1) { | ||
OUT_OF_SPACE_IF_NULL(self_or_null = sym_new_unknown(ctx)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point in the future we will be able to tell whether the attribute is a method or not, and hence we will be able to set it to either null
or not_null
-- but not today, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No not for _LOAD_ATTR - this opcode is special, it means we dont know anything and it's only decideable at runtime.
The test suite crashed without _LOAD_ATTR manual definition |
Changes the default symbol to
not-null
because in reality, most of the stuff in CPython pushes non-null to the stack.