Skip to content

gh-91636: Don't clear required fields of function objects #91651

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

Merged
merged 6 commits into from
Apr 21, 2022

Conversation

sweeneyde
Copy link
Member

@sweeneyde sweeneyde commented Apr 18, 2022

Py_CLEAR(op->func_module);
Py_CLEAR(op->func_defaults);
Py_CLEAR(op->func_kwdefaults);
Py_CLEAR(op->func_doc);
Py_CLEAR(op->func_dict);
Py_CLEAR(op->func_closure);
Py_CLEAR(op->func_annotations);
/* Below are required attributes, so to keep everything in
* a consistent state, don't clear them. They're immutable,
* so they can't participate in cycles anyway.
Copy link
Member

Choose a reason for hiding this comment

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

Did you confirm that Unicode subclass are not allowed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good catch, it can be a subclass:

>>> def f():
...     pass
...
>>> class S(str):
...     pass
...
>>> f.__name__ = S("???") # no error

I don't know what a good solution is.

@pablogsal
Copy link
Member

Does this require backports?

@sweeneyde sweeneyde added needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes and removed needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes labels Apr 21, 2022
@sweeneyde
Copy link
Member Author

sweeneyde commented Apr 21, 2022

3.10 and 3.9 have no &_Py_STR(empty)), so I don't think backporting is very straightforward. This is a contrived edge-case, so maybe it's best to only touch 3.11?

@sweeneyde sweeneyde merged commit f2b4e45 into python:main Apr 21, 2022
@sweeneyde sweeneyde deleted the func_clear branch April 21, 2022 06:06
@sweeneyde sweeneyde mentioned this pull request Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants