I want to make it like this:
>>> myfunc("strawberry")
ok
# myfunc only works with strawberry
I know that most people will answer with:
def myfunc(something):
if something == "strawberry":
print("ok")
But I want to do all this in the parameter setting.
Kind of like this:
def myfunc(something: OnlyThese["strawberry", "cake"]):
print("ok")
Although the code above is incorrect, I want to see if Python already has a feature like this.
typing.Literalis the standard annotation for what you tried to do withOnlyThese.