Python 3 Deep Dive: Part 4 Oop

class PositiveNumber: def __set_name__(self, owner, name): self.name = name def __get__(self, instance, owner): return instance.__dict__.get(self.name)

class LogPlugin(Plugin): def run(self): print("Logging...") python 3 deep dive part 4 oop

: An instance method responsible for customizing the newly created object. class PositiveNumber: def __set_name__(self

If a class defines how an instance behaves, a defines how a class behaves. Metaclasses allow you to intercept, modify, or validate class creation. name): self.name = name def __get__(self

A class method receives the class as its first argument, regardless of whether it is called on the class or an instance. This is implemented by a descriptor that binds to the class instead of the instance.