python - How to write multiple signature hints in PyCharm with Python3 -
i written function argument on left, similar built-in range
function
the problem is, how write type hints can show 2 way should invoked.
for example, when type command+p(ctrl+p) in range
function in pycharm(range object in py3, not problem):
self:range, stop: int ------------------------------------------------- self:range, start: int, stop: int, step: int=-1
but my_range
:
def my_range(start: int, stop: int = none, step: int=1): """ list_range(stop) list_range(start, stop, step) return list of integers start (default 0) stop, incrementing step (default 1). """ if stop none: start, stop = 0, start return list(range(start, stop, step))
after type command + p , got:
start: int, stop: optional[int], step: int=-1
does knows how implement that? many help!
try typing
module! it's got lot of helpers type annotations, including typing.optional
. use this:
import typing def f(required_arg: int, optional_arg:typing.optional[int]=none): # ...
Comments
Post a Comment