Skip to content

Add case_sensitive parameter to Choice.__init__ #12

Description

@todofixthis

Allow Choice to ignore case by passing an optional parameter to its __init__ method.

When applied, the filter should return the matching choice (i.e., automatically "fix" case mismatch).

Example:

>>> Choice(choices={'MOE', 'LARRY', 'CURLY', 'SHEMP'}, case_sensitive=False)\
...   .apply('Moe')
MOE # (changed to UPPERCASE to match valid choice)

Note that this yields a different result than using case folding:

>>> (CaseFold | Choice(choices={'MOE', 'LARRY', 'CURLY', 'SHEMP'}))\
...   .apply('Moe')
# Input is case-folded before Choice filter sees it, so it doesn't match anything.
FilterError: Valid options are: ['CURLY', 'LARRY', 'MOE', 'SHEMP']

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions