poprox_recommender.lkpipeline.types#

Functions

is_compatible_data(obj, *targets)

Make a best-effort check whether a type is compatible with at least one target type.

is_compatible_type(typ, *targets)

Make a best-effort check whether a type is compatible with at least one target type.

parse_type_string(tstr)

Compute a string representation of a type that is both resolvable and human-readable.

type_string(typ)

Compute a string representation of a type that is both resolvable and human-readable.

Classes

Lazy(*args, **kwargs)

Type for accepting lazy inputs from the pipeline runner.

Exceptions

TypecheckWarning

Warnings about type-checking logic.

exception poprox_recommender.lkpipeline.types.TypecheckWarning#

Bases: UserWarning

Warnings about type-checking logic.

class poprox_recommender.lkpipeline.types.Lazy(*args, **kwargs)#

Bases: Protocol, Generic[T]

Type for accepting lazy inputs from the pipeline runner. If your function may or may not need one of its inputs, declare the type with this to only run it as needed:

def my_component(input: str, backup: Lazy[str]) -> str:
    if input == 'invalid':
        return backup.get()
    else:
        return input
get()#

Get the value behind this lazy instance.

Return type:

T

poprox_recommender.lkpipeline.types.is_compatible_type(typ, *targets)#

Make a best-effort check whether a type is compatible with at least one target type. This function is limited by limitations of the Python type system and the effort required to (re-)write a full type checker. It is written to be over-accepting instead of over-restrictive, so it can be used to reject clearly incompatible types without rejecting combinations it cannot properly check.

Parameters:
  • typ (type) – The type to check.

  • targets (type) – One or more target types to check against.

Returns:

False if it is clear that the specified type is incompatible with all of the targets, and True otherwise.

Return type:

bool

poprox_recommender.lkpipeline.types.is_compatible_data(obj, *targets)#

Make a best-effort check whether a type is compatible with at least one target type. This function is limited by limitations of the Python type system and the effort required to (re-)write a full type checker. It is written to be over-accepting instead of over-restrictive, so it can be used to reject clearly incompatible types without rejecting combinations it cannot properly check.

Parameters:
  • typ – The type to check.

  • targets (type) – One or more target types to check against.

  • obj (object)

Returns:

False if it is clear that the specified type is incompatible with all of the targets, and True otherwise.

Return type:

bool

poprox_recommender.lkpipeline.types.type_string(typ)#

Compute a string representation of a type that is both resolvable and human-readable. Type parameterizations are lost.

Parameters:

typ (type | None)

Return type:

str

poprox_recommender.lkpipeline.types.parse_type_string(tstr)#

Compute a string representation of a type that is both resolvable and human-readable. Type parameterizations are lost.

Parameters:

tstr (str)

Return type:

type