Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New filter: NamedTuple #35

Open
todofixthis opened this issue Mar 7, 2018 · 0 comments
Open

New filter: NamedTuple #35

todofixthis opened this issue Mar 7, 2018 · 0 comments

Comments

@todofixthis
Copy link
Contributor

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)
todofixthis referenced this issue in todofixthis/filters Mar 8, 2018
todofixthis referenced this issue in todofixthis/filters Mar 8, 2018
todofixthis referenced this issue in todofixthis/filters Mar 8, 2018
todofixthis referenced this issue in todofixthis/filters Mar 8, 2018
todofixthis referenced this issue in todofixthis/filters Mar 8, 2018
todofixthis referenced this issue in todofixthis/filters Mar 11, 2018
It can contain other filters now, so it fits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant