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
I am looking at Python 3.10 and 3.11 docs on @staticmethod and it says "A static method can be called either on the class (such as C.f()) or on an instance (such as C().f()). Moreover, they can be called as regular functions (such as f())."
Say I have a class with a static method decorator:
class Foo:
@staticmethod
def a_num(*args):
return 'this is a number'
Foo.a_num() returns 'this is a number' likewise Foo().a_num() but just calling a_num() returns an error saying NameError: name 'a_num' is not defined. To my understanding, this contradicts the docs which says static methods can be called as regular functions without giving it an instance of the class i.e. f(). Is my understanding correct on this?
I have looked at 3.9 - 3.13 docs and only found this on 3.10 and 3.11. Is this a mistake or am I missing something? Thanks.
The text was updated successfully, but these errors were encountered:
I have looked at 3.9 - 3.13 docs and only found this on 3.10 and 3.11. Is this a mistake or am I missing something? Thanks.
We usually only make docs changes for Python versions in the bugfix phase (3.12-3.13) and rarely for those in the security-only phase (3.9-3.11), which is why the fix for the linked duplicate was only backported as far as 3.12.
I am looking at Python 3.10 and 3.11 docs on
@staticmethod
and it says "A static method can be called either on the class (such as C.f()) or on an instance (such as C().f()). Moreover, they can be called as regular functions (such as f())."Say I have a class with a static method decorator:
Foo.a_num()
returns'this is a number'
likewiseFoo().a_num()
but just callinga_num()
returns an error sayingNameError: name 'a_num' is not defined
. To my understanding, this contradicts the docs which says static methods can be called as regular functions without giving it an instance of the class i.e. f(). Is my understanding correct on this?I have looked at 3.9 - 3.13 docs and only found this on 3.10 and 3.11. Is this a mistake or am I missing something? Thanks.
The text was updated successfully, but these errors were encountered: