rats.annotations
¶
    General purpose library to attach annotations to functions.
Annotations are typically, but not exclusively, attached using decorators.
            DecoratorType = TypeVar('DecoratorType', bound=(Callable[..., Any]))
  
      module-attribute
  
¶
    
            T_GroupType = TypeVar('T_GroupType', bound=NamedTuple)
  
      module-attribute
  
¶
    
            __all__ = ['AnnotationsContainer', 'DecoratorType', 'GroupAnnotations', 'T_GroupType', 'annotation', 'get_annotations', 'get_class_annotations']
  
      module-attribute
  
¶
    
            AnnotationsContainer
¶
    
              Bases: NamedTuple
Holds metadata about the annotated functions or class methods.
Loosely inspired by: https://peps.python.org/pep-3107/.
            GroupAnnotations
¶
    
              Bases: ExtNamedTuple, Generic[T_GroupType]
The list of T_GroupType objects identified by a given name in a namespace.
            annotation(namespace, group_id)
¶
    Decorator to add an annotation to a function.
Typically used to create domain-specific annotation functions for things like DI Containers. For examples, see the rats.apps annotations, like service() and group().
Source code in rats/annotations/_functions.py
              
            get_annotations(fn)
¶
    Get all annotations for a function or class method.
Builds an instance of AnnotationsContainer from the annotations found in the object's "rats_annotations" attribute.
Source code in rats/annotations/_functions.py
              
            get_class_annotations(cls)
  
      cached
  
¶
    Get all annotations for a class.
Traverses the class methods looking for any annotated with "rats_annotations" and returns an instance of AnnotationsContainer. This function tries to cache the results to avoid any expensive parsing of the class methods.