E
Size: a a a
E
A🚀
Б
@property
that behaves differently when it's called from the class and when from the instance.from types import DynamicClassAttribute
class Meta(type):
@property
def hello(cls):
return f'hello from Meta ({cls})'
class C(metaclass=Meta):
@DynamicClassAttribute
def hello(self):
return f'hello from C ({self})'
C.hello
# "hello from Meta (<class '__main__.C'>)"
C().hello
# 'hello from C (<__main__.C object ...)'
enum
to provide name
and value
properties for instances while still allowing to have name
and value
class members:import enum
class E(enum.Enum):
value = 1
E.value
# <E.value: 1>
E.value.value
# 1
Б
@property
that behaves differently when it's called from the class and when from the instance.from types import DynamicClassAttribute
class Meta(type):
@property
def hello(cls):
return f'hello from Meta ({cls})'
class C(metaclass=Meta):
@DynamicClassAttribute
def hello(self):
return f'hello from C ({self})'
C.hello
# "hello from Meta (<class '__main__.C'>)"
C().hello
# 'hello from C (<__main__.C object ...)'
enum
to provide name
and value
properties for instances while still allowing to have name
and value
class members:import enum
class E(enum.Enum):
value = 1
E.value
# <E.value: 1>
E.value.value
# 1
Б
Б
@property
that behaves differently when it's called from the class and when from the instance.from types import DynamicClassAttribute
class Meta(type):
@property
def hello(cls):
return f'hello from Meta ({cls})'
class C(metaclass=Meta):
@DynamicClassAttribute
def hello(self):
return f'hello from C ({self})'
C.hello
# "hello from Meta (<class '__main__.C'>)"
C().hello
# 'hello from C (<__main__.C object ...)'
enum
to provide name
and value
properties for instances while still allowing to have name
and value
class members:import enum
class E(enum.Enum):
value = 1
E.value
# <E.value: 1>
E.value.value
# 1
DynamicClassAttribute
для енума, для меня загадкаclass Meta(type):
@property
def hello(cls):
return f'hello from Meta ({cls})'
class C(metaclass=Meta):
def __init__(self):
self.hello = f'hello from C ({self})'
assert C.hello == f'hello from Meta ({C})'
c = C()
assert c.hello == f'hello from C ({c})'
p
AZ
E
AZ
E
AZ
E
VA
RC
E
E
DB
Retry in 5 seconds
, Retry in 10 seconds
-> Retry in %d seconds
DB