Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-144330: Initialize classmethod and staticmethod in new#144469

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
vstinner wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromvstinner:cm_new

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commentedFeb 4, 2026
edited
Loading

Move classmethod and staticmethod initialization frominit() tonew().

PyClassMethod_New() and PyStaticMethod_New() now copy attributes of the wrapped functions:__module__,__name__,__qualname__ and__doc__.

Change static type initialization: initialize PyStaticMethod_Type and PyCFunction_Type earlier.

Remove test_refleaks_in_classmethod___init__() and test_refleaks_in_staticmethod___init__() tests from test_descr since classmethod and staticmethod have no__init__() method anymore.

Move classmethod and staticmethod initialization from __init__() to__new__().PyClassMethod_New() and PyStaticMethod_New() now copy attributes ofthe wrapped functions: __module__, __name__, __qualname__ and__doc__.Change static type initialization: initialize PyStaticMethod_Type andPyCFunction_Type earlier.Remove test_refleaks_in_classmethod___init__() andtest_refleaks_in_staticmethod___init__() tests from test_descr sinceclassmethod and staticmethod have no __init__() method anymore.
@vstinner
Copy link
MemberAuthor

cc@colesbury

@vstinner
Copy link
MemberAuthor

With this change,cm->cm_callable andsm->sm_callable cannot beNULL anymore (except incm_dealloc() andsm_dealloc() to handle erros incm_new() andsm_new()), but they can be equal toNone:cm_new() andsm_new() don't check thecallable type (no change compared to the current code).

cm_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
classmethod *cm = (classmethod *)self;

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add an assert here likeassert(cm->cm_callable != NULL)?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I would prefer to not add an assertion sincecm->cm_callable is used in multiple places without checking that it's notNULL. With this change,cm->cm_callable cannot beNULL anymore. In practice, it can beNULL ifcm_new() fails: onlycm_dealloc() has to deal withNULL.

sm_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
staticmethod *sm = (staticmethod *)self;

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@sergey-miryanovsergey-miryanovsergey-miryanov left review comments

@ZeroIntensityZeroIntensityAwaiting requested review from ZeroIntensityZeroIntensity is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@sergey-miryanov

[8]ページ先頭

©2009-2026 Movatter.jp