From 708d926e6ca2337fc01d3f2926da883c67edf5e2 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Tue, 9 Sep 2025 21:44:55 +0800 Subject: [PATCH] feat: add python_annotation_test.py --- python_annotation_test.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 python_annotation_test.py diff --git a/python_annotation_test.py b/python_annotation_test.py new file mode 100644 index 0000000..b185c8b --- /dev/null +++ b/python_annotation_test.py @@ -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)