You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
classmethod and staticmethod can crash with NULL / uninitialized callables #144330
The problem is that sm_callable/cm_callable fields are only initialized in the __init__ function and not all code (like the repr) handles the NULL case.
Additionally, even though __func__ isn't writable, you can modify it by calling __init__ on an already initialized staticmethod or classmethod.
Activity
colesbury commentedon Jan 29, 2026
For 3.15, it would be nice to move the initialization to a
tp_newinstead oftp_initand avoid all these problemsAniketsy commentedon Jan 30, 2026
I’d be happy to work on this, as suggested.
skirpichev commentedon Jan 30, 2026
I think we can't do this without prior deprecation, no? See #143715 for similar case.
pythongh-144330: Initialize classmethod and staticmethod in new
vstinner commentedon Feb 4, 2026
@colesbury:
I wrote PR gh-144469 to implement this change.
gh-144330: Initialize classmethod and staticmethod in new (#144469)
vstinner commentedon Feb 5, 2026
Oh, 3.13 and 3.14 are also affected, I reopen the issue.
I wrote a simpler fix for 3.13 and 3.14: #144498
pythongh-144330: Initialize classmethod and staticmethod in new
pythongh-144330: Initialize classmethod and staticmethod in new (pyth…
[3.14] gh-144330: Initialize classmethod and staticmethod in new (#14…
[3.14] pythongh-144330: Initialize classmethod and staticmethod in new (
[3.13] gh-144330: Initialize classmethod and staticmethod in new (GH-…
StanFromIreland commentedon Feb 7, 2026
Victor's backports were merged.
pythongh-144330: Initialize classmethod and staticmethod in new (pyth…
pythongh-144330: Initialize classmethod and staticmethod in new (pyth…