Use literals as the type for cli opts that take choices

This commit is contained in:
Kovid Goyal 2020-04-24 15:28:04 +05:30
parent 3c1954f329
commit 0eef48b516
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -409,6 +409,9 @@ def as_type_stub(seq: OptionSpecSeq, disabled: OptionSpecSeq, class_name: str, e
elif otype == 'list': elif otype == 'list':
t = 'typing.Sequence[str]' t = 'typing.Sequence[str]'
elif otype in ('choice', 'choices'): elif otype in ('choice', 'choices'):
if opt['choices']:
t = 'typing.Literal[{}]'.format(','.join(f'{x!r}' for x in opt['choices']))
else:
t = 'str' t = 'str'
elif otype.startswith('bool-'): elif otype.startswith('bool-'):
t = 'bool' t = 'bool'