Skip to content
Snippets Groups Projects
Forked from Platform / Development / swh-model
Source project has a limited visibility.
  • vlorentz's avatar
    76b744e0
    model: Make all classes slotted. · 76b744e0
    vlorentz authored
    Unfortunately, sphinx (actually, autodoc) only picks up attributes if
    they fall in any of these cases:
    
    1. are enum variants
    2. are in slots
    3. are in __dict__
    4. have an annotation
    5. are found using its custom parser
    
    (see get_object_members in sphinx/ext/autodoc/importer.py)
    
    In theory, option 5 should work for us; unfortunately, autodoc only
    asks the parser the list of members with a comment.
    And it's not easy to adapt it to ask the parser for all members,
    because said parser (sphinx/pycode/parser.py) does not return the class
    qualname (aka. namespace) for members without comments.
    
    So, as I don't want to change the interface of sphinx.pycode.parser,
    this commit switches to relying on option 3, by adding __slots__ for
    all attr classes.
    
    Additionally, this might have some performance/memory improvement
    (though I did not check) and will further avoid mutation of these
    objects.
    76b744e0
    History
    model: Make all classes slotted.
    vlorentz authored
    Unfortunately, sphinx (actually, autodoc) only picks up attributes if
    they fall in any of these cases:
    
    1. are enum variants
    2. are in slots
    3. are in __dict__
    4. have an annotation
    5. are found using its custom parser
    
    (see get_object_members in sphinx/ext/autodoc/importer.py)
    
    In theory, option 5 should work for us; unfortunately, autodoc only
    asks the parser the list of members with a comment.
    And it's not easy to adapt it to ask the parser for all members,
    because said parser (sphinx/pycode/parser.py) does not return the class
    qualname (aka. namespace) for members without comments.
    
    So, as I don't want to change the interface of sphinx.pycode.parser,
    this commit switches to relying on option 3, by adding __slots__ for
    all attr classes.
    
    Additionally, this might have some performance/memory improvement
    (though I did not check) and will further avoid mutation of these
    objects.