May-25-2023, 10:47 AM
Example with first function,the
There a two return,so need to address both in Return type.
Don't know about your converting in last part,would add that in new function that if needed.
Will get less readable if clutter to much in and the addition difficulty to get Type hint to work together.
Tuple[Optional
is not needed if use Python 3.10 or newer.There a two return,so need to address both in Return type.
# pre.py from typing import AnyStr def func(a: AnyStr, *b: AnyStr) -> tuple[AnyStr, AnyStr] | tuple[None, AnyStr]: for _b in b: if a.startswith(_b): return _b, a.removeprefix(_b) return None, a a = 'test123' b = 'test1' print(func(a, b))Test using mypy.
G:\div_code\hex λ mypy pre.py Success: no issues found in 1 source file G:\div_code\hex λ python pre.py ('test1', '23')So now it work for string and bytes.
Don't know about your converting in last part,would add that in new function that if needed.
Will get less readable if clutter to much in and the addition difficulty to get Type hint to work together.