This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Clarify the behavior of the staticmethod builtin
Type: enhancement Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: adelfino, docs@python, haikuginger, rhettinger
Priority: normal Keywords:

Created on 2017-11-18 18:04 by haikuginger, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4362 merged haikuginger, 2017-11-18 18:04
Messages (3)
msg306489 - (view) Author: Jesse Shapiro (haikuginger) * Date: 2017-11-18 18:04
It looks like the original staticmethod docstring might have been based on the classmethod docstring, and it seems like the current description might not be accurate.

Current string:

...It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()); the instance is ignored except for its class...

Proposed change:

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). Both the class and the instance are ignored, and neither is passed implicitly as the first argument to the method.
msg306505 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-11-19 17:13
ISTM the current wording is correct and aims to describe how staticmethods differ from regular methods.   With a regular methods we have "c.m(*a) -> type(c).m(c, *a)" and "C.m(*a) -> C.m(*s)".  With a class method, only the first of those changes to "c.m(*a) -> type(c).m(*a)". Expressed in English, this change is "the instance is ignored except for its class...".

That said, the staticmethod() docs could use a complete rewrite.  They amble all over the place and don't directly speak to what a static method is for (attaching regular functions to classes to improve findability) or how they work (use descriptor logic to suppress the usual behavior of prepend "self" to the argument list when called from an instance) or a concise motivating example.
msg332513 - (view) Author: Andrés Delfino (adelfino) * (Python triager) Date: 2018-12-25 18:30
Also see #34085 that deals with the same issue in functions.rst.
History
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76251
2018-12-25 18:30:53adelfinosetnosy: + adelfino
messages: + msg332513
2018-12-24 07:47:56rhettingersetstatus: open -> closed
resolution: fixed
stage: resolved
2017-11-19 17:13:33rhettingersetnosy: + rhettinger
messages: + msg306505
2017-11-18 18:04:14haikugingercreate