Search⌘ K
AI Features

Non-Reflexive Class Method

Understand why accessing a Python class method creates a new bound method each time and how this affects method identity. Learn to recognize non-reflexive behavior in class methods to improve your grasp of Python's internals.

We'll cover the following...

Class methods can be puzzling at times.

Python 3.5
class SomeClass:
def instance_method(self):
pass
@classmethod
def class_method(cls):
pass
print(SomeClass.instance_method is SomeClass.instance_method)
print(SomeClass.class_method is SomeClass.class_method)
print(id(SomeClass.class_method) == id(SomeClass.class_method))

Explanation

  • The reason SomeClass.class_method is SomeClass.class_method is False
...