pyAttributes Module

pyAttributes

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.Func

A type variable for functions. Here it’s used for methods.

alias of TypeVar(‘Func’)

pyAttributes.TAttr

A type variable for Attribute.

alias of TypeVar(‘TAttr’)

pyAttributes.TAttributeFilter

A type hint for a filter 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.

__call__(func)[source]

Make all classes derived from Attribute callable, so they can be used as a decorator.

Return type

~Func

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, filter=<class 'pyAttributes.Attribute'>)[source]

Returns true, if the given method has pyAttributes attached.

Return type

bool

static GetAttributes(method, filter=<class 'pyAttributes.Attribute'>)[source]

Returns a list of pyAttributes attached to the given method.

Return type

List[~TAttr]