Skip to content

New filter: NamedTuple #35

Description

@todofixthis

Implement a new filter that, given a collections.namedtuple type, attempts to convert the incoming value into that type.

Examples:

Colour = namedtuple('Colour', ('r', 'g', 'b', 'a'))

f.NamedTuple(Colour).apply([96, 96, 192, 1.0])  # Colour(r=96, g=96, b=192, a=1.0)
f.NamedTuple(Colour).apply('1234')  # Colour(r='1', g='2', b='3', a='4')
f.NamedTuple(Colour).apply({'r': 96, 'g': 96, 'b': 192, 'a': 1.0})  # Colour(r=96, g=96, b=192, a=1.0)

f.NamedTuple(Colour).apply([0])  # FilterError (not enough values)
f.NamedTuple(Colour).apply([0]*5)  # FilterError (too many values)
f.NamedTuple(Colour).apply({"c": 192, "m": 36, "y": 192, "k": 68})  # FilterError (wrong keys)
f.NamedTuple(Colour).apply(42)  # FilterError (wrong type)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions