I am passing a data_type
parameter to many python functions/methods/classes. It can take one of a small number of string values.
I could type hint it using Literal
<code>from typing import Literal
data_type: Literal["type1", "type2", "type3", "type4"]
</code>
<code>from typing import Literal
data_type: Literal["type1", "type2", "type3", "type4"]
</code>
from typing import Literal
data_type: Literal["type1", "type2", "type3", "type4"]
But then if I add a new data type, I need to update this Literal
type hint everywhere.
Does this violate the Don’t Repeat Yourself (DRY) principle? What are some best practice ways to get around this?
1