AnyIO’s Typed Attributes

Backport of AnyIO’s typed attributes.

class easynetwork.lowlevel.typed_attr.TypedAttributeProvider

Bases: object

Base class for classes that wish to provide typed extra attributes.

property extra_attributes: Mapping[Any, Callable[[], Any]]

A mapping of the extra attributes to callables that return the corresponding values.

If the provider wraps another provider, the attributes from that wrapper should also be included in the returned mapping (but the wrapper may override the callables from the wrapped instance).

The callables should raise TypedAttributeLookupError if it is not possible to get the value.

final extra(attribute: _T_Attr) _T_Attr
final extra(attribute: _T_Attr, default: _T_Default) _T_Attr | _T_Default

Return the value of the given typed extra attribute.

Parameters:
  • attribute – the attribute (member of a TypedAttributeSet) to look for

  • default – the value that should be returned if no value is found for the attribute

Raises:

TypedAttributeLookupError – if the search failed and no default value was given

class easynetwork.lowlevel.typed_attr.TypedAttributeSet

Bases: object

Superclass for typed attribute collections.

Checks that every public attribute of every subclass has a type annotation.