Skip to content

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

Merged
sweeneyde merged 6 commits into
python:mainfrom
sweeneyde:func_clear
Apr 21, 2022
Merged

sweeneyde merged 6 commits into
python:mainfrom
sweeneyde:func_clear

Conversation

@sweeneyde

@sweeneyde sweeneyde commented Apr 18, 2022 •

Copy link
Copy Markdown
Member

Comment thread Objects/funcobject.c Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Does this require backports?

@sweeneyde

sweeneyde commented Apr 21, 2022 •

Copy link
Copy Markdown
Member Author

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