feat: add python_annotation_test.py
This commit is contained in:
37
python_annotation_test.py
Normal file
37
python_annotation_test.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
def attr(cls):
|
||||||
|
cls._attr1 = 'test'
|
||||||
|
return cls
|
||||||
|
|
||||||
|
|
||||||
|
def attr2(*, name=None):
|
||||||
|
def attr2_cls(cls):
|
||||||
|
cls._attr_name_1 = name
|
||||||
|
return cls
|
||||||
|
|
||||||
|
return attr2_cls
|
||||||
|
|
||||||
|
|
||||||
|
class Attr:
|
||||||
|
controllers = []
|
||||||
|
|
||||||
|
def __init__(self, *, name=None):
|
||||||
|
self.__name = name
|
||||||
|
|
||||||
|
def __call__(self, cls):
|
||||||
|
Attr.controllers.append(cls)
|
||||||
|
cls._attr_name_2 = self.__name
|
||||||
|
return cls
|
||||||
|
|
||||||
|
|
||||||
|
@Attr(name='test2')
|
||||||
|
@attr2(name='test1')
|
||||||
|
@attr
|
||||||
|
class Class1:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(getattr(Class1, '_attr1'))
|
||||||
|
print(getattr(Class1, '_attr_name_1'))
|
||||||
|
print(getattr(Class1, '_attr_name_2'))
|
||||||
|
print(Attr.controllers)
|
||||||
Reference in New Issue
Block a user