titus.signature.Sig

class titus.signature.Sig(params, ret, lifespan=<titus.signature.Lifespan object at 0x7faece856450>)[source]

Bases: titus.signature.Signature

PFA function signature for a single pattern.

This class can either be used directly as a function’s only signature or it may be contained within a titus.signature.Sigs.

__init__(params, ret, lifespan=<titus.signature.Lifespan object at 0x7faece856450>)
Parameters:
  • params (list of titus.P) – patterns for each argument (in order)
  • ret (titus.P) – pattern for the return type
  • lifespan (titus.signature.Lifespan) – validity range for this signature; default is eternal (existing from the beginning of time to the end of time)
accepts(args, version)

Determine if this signature accepts the given arguments for a given PFA version number.

Parameters:
  • args (list of titus.datatype.AvroType) – arguments to match against the signature pattern
  • version (titus.signature.PFAVersion) – PFA version number in which to interpret the pattern
Return type:

(titus.signature.Sig, list of titus.datatype.AvroType, AvroType)

Returns:

(self, resolved argument types, resolved return type) if this signature accepts the arguments; None otherwise

assign(pat, arg, assignments)

Apply the label assignments (e.g. “A” matched to “int”, “B” matched to “string”, etc.) to each parameter of the signature.

Parameters:
  • pat (titus.P) – original parameter pattern
  • arg (titus.datatype.AvroType) – supplied argument type
  • assignments (dict from label letters to titus.datatype.AvroType) – assigned types to apply
Return type:

titus.datatype.AvroType

Returns:

resolved type for one parameter of the signature

assignRet(pat, assignments)

Apply the label assignments (e.g. “A” matched to “int”, “B” matched to “string” etc.) to the return pattern.

Parameters:
  • pat (titus.P) – original return pattern
  • assignments (dict from label letters to titus.datatype.AvroType) – assigned types to apply
Return type:

titus.datatype.AvroType

Returns:

resolved type for the return value of the signature

check(pat, arg, labelData, strict, reversed)

Determine if a single slot in the parameter pattern matches a single argument’s type.

Parameters:
  • pat (titus.P) – pattern for a type that can include wildcards, etc.
  • arg (titus.datatype.AvroType) – supplied argument type that may or may not fit the pattern
  • labelData (dict from label letters to titus.signature.LabelData) – label associations made so far (so that repeated label letters are forced to resolve to the same types)
  • strict (boolean) – if True, don’t allow subtypes to match supertypes
Return type:

bool

Returns:

True if arg matches pat; False otherwise