parasite.never

Brief

Reference for the never submodule of the parasite package. This submodule contains the Never class, which is a simple class that always raises a ValidationError when called.

Usage

from parasite import p

schema = p.never()
schema.parse(1)  # ValidationError: this type can never be parsed
...

schema = p.obj({ "name": p.never() })
schema.parse({ "name": "John" })  # ValidationError: key "name" found, but this type can never be parsed
...

Member Reference

class parasite.never.K

Template type for the key in a dictionary.

alias of TypeVar(‘K’)

class parasite.never.Never[source]

Bases: ParasiteType[None]

Parasite type for representing never values.

Note

Please use p.never() instead of instantiating this class directly. p can be imported with:

from parasite import p

schema = p.never()
...
parse(obj: Any) None[source]

Default method for parsing a value. This method should be overridden by subclasses.

Throws:

ValidationError: if the value could not be parsed or was invalid

Parameters:

obj (Any) – value to parse

Returns:

parsed destination value

Return type:

T

parse_safe(obj: Any) Result[T, ValidationError]

Converts the result of parse() into a rusttypes.result.Result type. Should be used when safe parsing is required.

Note

Will only catch parasite.errors.ValidationError exceptions!!!

Parameters:

obj (Any) – value to parse

Returns:

parsed destination value or an error

Return type:

Result[T, ValidationError]