pyAttributes Module
This Python module offers the base implementation of .NET-like attributes
realized with Python decorators. This module comes also with a mixin-class
to ease using classes having annotated methods.
The decorators in pyAttributes are implemented as class-based decorators.
The annotated data is stored in an additional __dict__
entry for each
annotated method. By default the entry is called __pyattr__
.
-
pyAttributes.TAttr
A type variable for Attribute
.
alias of TypeVar(‘TAttr’, bound=Attribute
)
-
pyAttributes.TAttributeFilter
A type hint for a predicate parameter that accepts either a single Attribute
or an iterable of those.
alias of Optional
[Union
[TAttr
, Iterable
[TAttr
]]]
Attribute
-
class pyAttributes.Attribute[source]
Bases: object
Base-class for all pyAttributes.
-
_classes: List[Any] = []
List of classes, this pyAttribute was attached to.
-
__call__(entity)[source]
Make all classes derived from Attribute
callable, so they can be used as a decorator.
- Return type:
TypeVar
(Entity
, bound= Union
[Type
, Callable
])
-
static _AppendAttribute(entity, attribute)[source]
Helper method, to attach a given pyAttribute to an entity (function, class, method).
- Return type:
None
-
classmethod GetClasses(scope=None, predicate=None)[source]
Return a generator for all classes, where this attribute was attached to.
- The resulting item stream can be filtered by:
-
- Return type:
Generator
[Type
, None
, None
]
-
classmethod GetAttributes(method, includeSubClasses=True)[source]
Returns attached attributes for a given method.
- Return type:
List
[Attribute
]
AttributeHelperMixin
-
class pyAttributes.AttributeHelperMixin[source]
Bases: object
A mixin class to ease finding methods with attached pyAttributes.
-
static HasAttribute(method, predicate=<class 'pyAttributes.Attribute'>)[source]
Returns true, if the given method has pyAttributes attached.
- Return type:
bool
-
static GetAttributes(method, predicate=<class 'pyAttributes.Attribute'>)[source]
Returns a list of pyAttributes attached to the given method.
- Return type:
List
[TypeVar
(TAttr
, bound= Attribute)]