misc
Collection of convenience classes that do not fit any other category.
- class ArgRepr(*args, **kwargs)[source]
Bases:
ReprNameBase class for a representation with class name and (keyword) arguments.
This class is not meant to be instantiated by itself. Rather, it is meant to be inherited from. Its constructor is then meant to be called in the child’s constructor (with
super().__init__(...)), passing the (keyword) arguments that are desired to appear in the child’s representation.- Parameters:
*args – Appear as arguments within parentheses in the child representation after its class name.
**kwargs – Appear as keyword arguments within parentheses in the child representation after its class name and arguments.
Examples
>>> class Pretty(ArgRepr): ... def __init__(self, foo, answer): ... super().__init__(foo, answer=answer) ... >>> Pretty('good', 42) Pretty('good', answer=42)
- static _name(obj)
Representation for callable objects used for, e.g., error messages.
- Parameters:
obj (callable) – Any callable object, e.g., a class, function, method, or lambda
- Returns:
A human-readable representation of the callable obj.
- Return type:
str
- class IndentRepr(items=(), *args, **kwargs)[source]
Bases:
ReprNameBase class for a representation with numbered and indented children.
This class is not meant to be instantiated by itself. Rather, it is meant to be inherited from. Its constructor is then meant to be called in the child’s constructor (with
super().__init__(...)), passing as arguments all items that are desired to appear in a (zero-based) numbered-list representation. If any of these objects have inherited fromIndentReprthemselves, their representation will recursively be indented by another level. Additional (keyword) arguments will be included in the first line of the representation.- Parameters:
items (sequence, optional) – Objects to represent in a (zero-based) numbered list below the class. Defaults to an emtpy tuple.
*args – Additional arguments to appear in the class instantiation signature in the first line of the representation.
**kwargs – Additional keyword arguments to appear in the class instantiation signature in the first line of the representation.
Examples
>>> class Fancy(IndentRepr): ... def __init__(self, foo, *args, **kwargs) -> None: ... super().__init__(args, foo, **kwargs) ... >>> Fancy('bar', 1, 2, Fancy('baz', 3, 4), 5, answer=42) Fancy('bar', answer=42): [ 0] 1 [ 1] 2 [ 2] Fancy('baz'): [ 0] 3 [ 1] 4 [ 3] 5
- static _name(obj)
Representation for callable objects used for, e.g., error messages.
- Parameters:
obj (callable) – Any callable object, e.g., a class, function, method, or lambda
- Returns:
A human-readable representation of the callable obj.
- Return type:
str