I'd like to construct a type hint for a sequence of string literals which could accept each of the literals but any literal couldn't occur more than once in the sequence.
I've tried to look for existing solutions and in the standard docs but so far without luck.
This is what I'm trying to accomplish:
from typing import Literal, Sequence
MyValues = Literal["a", "b", "c"]
def my_function(values: Sequence[MyValues]):
pass
my_function(values=[])
my_function(values=["a", "b"])
my_function(values=["a", "b", "a"]) # should fail type checking
In the above example all function calls pass type checking, which is expected. However during a third case I'd like to see an error which tells me that the literal "a"
occurs more than once in the sequence.
I'm not sure if it's even possible but I'm curious if anyone has an idea how to workaround this issue.
Obviously I can filter out duplicates in the function body, but in this case the main idea is to catch such mistakes during development time.