Diagnostic API for Python#
Applications not only produce results, formatted according to their own JSON schema, but they can also generate diagnostics. These are messages that the application can use to signal events such as errors, warnings, notes, etc.
In our framework, the core class is Diagnostic
which holds all relevant information. Among this is the type of the diagnostic. This can be any integer type, but for convenience, it defaults to the levels defined by the DiagnosticType
integer enumeration type.
- class eot.wowool.diagnostic.DiagnosticType#
DiagnosticType
is an enumeration type that holds the diagnostic types supported by default. The included levels map to the levels provided by the logging libraryNote
This enumeration type can be extended or replaced with any other integer type
- Debug = 10#
- Info = 20#
- Warning = 30#
- Error = 40#
- Critical = 50#
- Notset = 0#
- classmethod names() List[str] #
- Returns
The diagnostic names, sorted by level value (
int
)- Return type
A
list
ofstr
- classmethod all()#
- Returns
All type enumerations
- Return type
A
list
ofint
- classmethod count() int #
- Returns
The number of types
- Return type
int
- __new__(value)#
- class eot.wowool.diagnostic.Diagnostic#
Diagnostic
is a class that holds all relevant diagnostical informationNote
The
type
parameter can be any integer type. For convenience sake,DiagnosticType
is used by default, but you can provide your own typing scheme- static from_json(json: dict)#
- __init__(id: Union[str, int], message: str, type: SupportsInt, line: Optional[int] = None, offset: Optional[int] = None)#
Initialize a
Diagnostic
instance- Parameters
id (
str
orint
) – Unique identifiermessage (
str
) – Messageline (
int
) – Line number (optional)offset (
int
) – Offset (optional)
- to_json()#
- Returns
A dictionary representing a JSON object of the diagnostic
- Return type
dict
- to_exception()#
- rich()#
- Returns
The rich string representation of the token
- Return type
str
- class eot.wowool.diagnostic.Diagnostics#
Diagnostics
is a convenience class that provides some commonly used functionality and acts as a facade- static from_json(json: list)#
- __init__(items: List[eot.wowool.diagnostic.Diagnostic] = None)#
Initialize a
Diagnostics
instance- Params items
Diagnostics. Defaults to an empty list
- add(diagnostic: eot.wowool.diagnostic.Diagnostic)#
Add a diagnostic
- Parameters
diagnostic (
Diagnostic
) – Diagnostic
- extend(diagnostics)#
Extend with given diagnostics
- Parameters
diagnostic (
Diagnostics
) – Diagnostics
- filter(type: SupportsInt)#
Filter on a given diagnostic type
- Parameters
type (
DiagnosticType
orint
) – Diagnostic type- Returns
A generator expression yielding diagnostics of the matching type
- Return type
- has(type: SupportsInt) bool #
- Returns
Whether a diagnostic with the given type is present
- Return type
bool
- __iter__()#
- raise_when(type: SupportsInt)#
Raises an exception when a diagnostic exceeds the level of the given type
- Raises
DiagnosticException – Only in presence of a diagnostic level that exceeds the given type
- is_greater_or_equal_than(type: SupportsInt)#
- Returns
Whether a diagnostic is greater or equal than the given diagnostic type
- Return type
bool
- to_json()#
- __getitem__(index)#