Skip to content

gh-144330: Initialize staticmethod/classmethod callables in tp_new#144440

Closed
Aniketsy wants to merge 3 commits into
python:mainfrom
Aniketsy:fix-144330-clean
Closed

gh-144330: Initialize staticmethod/classmethod callables in tp_new#144440
Aniketsy wants to merge 3 commits into
python:mainfrom
Aniketsy:fix-144330-clean

Conversation

@Aniketsy

@Aniketsy Aniketsy commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

@Aniketsy

Aniketsy commented Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

@vstinner Apologies for the previous PR. I’ve addressed the review suggestions in this one. Thanks!

Comment thread Objects/funcobject.c
if (cm == NULL) {
return NULL;
}
cm->cm_callable = Py_None;

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.

With this change, cm->cm_callable cannot be NULL anymore:

  • cm_repr(): So you can remove cm->cm_callable != NULL (revert your change).
  • cm_dealloc(): Py_XDECREF(cm->cm_callable); can be replaced with Py_DECREF(cm->cm_callable);.
  • cm_descr_get(): I suggest to replace if (cm->cm_callable == NULL) with if (cm->cm_callable == Py_None).
  • cm_init(): replace Py_XSETREF(cm->cm_callable, ...) with Py_SETREF(cm->cm_callable, ...).

@vstinner

vstinner commented Feb 4, 2026

Copy link
Copy Markdown
Member

I wrote a different approach: parse arguments in cm_new()/sm_new(): PR gh-144469.

@vstinner

vstinner commented Feb 5, 2026

Copy link
Copy Markdown
Member

I merged #144469 instead. Thanks for your contribution anyway!

@vstinner vstinner closed this Feb 5, 2026
@vstinner

vstinner commented Feb 5, 2026

Copy link
Copy Markdown
Member

I wrote a simpler change for 3.13 and 3.14: #144498 I added you as a co-author since I copied some code from your PR.

@Aniketsy

Aniketsy commented Feb 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks

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.

2 participants