Skip to content
Snippets Groups Projects

Collect tagged (decorated) methods

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Pietro Saccardi

    Metaclass and decorators that can actually collect hierarchies of tagged members into a class attribute

    Edited
    output.log 893 B
    Taggable.TAGGED_MEMBERS.parent_classes: []
    Taggable.TAGGED_MEMBERS.attribute_names: []
    Taggable.TAGGED_MEMBERS.hierarchy_attribute_names(): set()
    Test.TAGGED_MEMBERS.parent_classes: [<class '__main__.Taggable'>]
    Test.TAGGED_MEMBERS.attribute_names: ['foobar', 'barbaz']
    Test.TAGGED_MEMBERS.hierarchy_attribute_names(): {'foobar', 'barbaz'}
    TestChild.TAGGED_MEMBERS.parent_classes: [<class '__main__.Test'>]
    TestChild.TAGGED_MEMBERS.attribute_names: ['baz']
    TestChild.TAGGED_MEMBERS.hierarchy_attribute_names(): {'baz', 'foobar', 'barbaz'}
    TestChild.foobar: <property object at 0x7f95925ad3b0>
    TestChild.barbaz: <function Test.barbaz at 0x7f9592593550>
    TestChild.baz: <property object at 0x7f95925ad450>
    instance.foobar: 5
    instance.barbaz: <bound method Test.barbaz of <__main__.TestChild object at 0x7f95925aa6d0>>
    instance.baz: hellow
    instance.barbaz(): 55
    
    Process finished with exit code 0
    tag.py 4.32 KiB
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment