mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Add typesepc_to_str function to mitmproxy/utils/typechck.py
This commit is contained in:
parent
2c0f6c2023
commit
1177e6d907
@ -425,14 +425,7 @@ def dump_dicts(opts):
|
|||||||
options_list = []
|
options_list = []
|
||||||
for k in sorted(opts.keys()):
|
for k in sorted(opts.keys()):
|
||||||
o = opts._options[k]
|
o = opts._options[k]
|
||||||
if o.typespec in (str, int, bool):
|
t = typecheck.typespec_to_str(o.typespec)
|
||||||
t = o.typespec.__name__
|
|
||||||
elif o.typespec == typing.Optional[str]:
|
|
||||||
t = 'Union'
|
|
||||||
elif o.typespec == typing.Sequence[str]:
|
|
||||||
t = 'Sequence'
|
|
||||||
else:
|
|
||||||
raise NotImplementedError
|
|
||||||
option = {
|
option = {
|
||||||
'name': k,
|
'name': k,
|
||||||
'type': t,
|
'type': t,
|
||||||
|
@ -98,3 +98,15 @@ def check_option_type(name: str, value: typing.Any, typeinfo: typing.Any) -> Non
|
|||||||
return
|
return
|
||||||
elif not isinstance(value, typeinfo):
|
elif not isinstance(value, typeinfo):
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
|
def typespec_to_str(typespec: typing.Any) -> str:
|
||||||
|
if typespec in (str, int, bool):
|
||||||
|
t = typespec.__name__
|
||||||
|
elif typespec == typing.Optional[str]:
|
||||||
|
t = 'Union'
|
||||||
|
elif typespec == typing.Sequence[str]:
|
||||||
|
t = 'Sequence'
|
||||||
|
else:
|
||||||
|
raise NotImplementedError
|
||||||
|
return t
|
||||||
|
Loading…
Reference in New Issue
Block a user