Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python typing list of specific values

# use typing.Literal - mode expects either 'a' or 'b'
from typing import Literal

def func(mode: Literal['a', 'b'] = 'a'):
    if mode not in ['a', 'b']:
        raise AttributeError('Not OK')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #typing #list #specific #values
ADD COMMENT
Topic
Name
4+8 =