I wrote a function with an argument to the left, just like an inline function range
The problem is how to write type hints that can show the two ways in which it should be called.
For example, when I write Command + p (Ctrl + p) in rangein PyCharm (range is an object in py3, but this is not a problem):
self:range, stop: int
self:range, start: int, stop: int, step: int=-1

But for 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 from start (default 0) to stop,
incrementing by step (default 1).
"""
if stop is None:
start, stop = 0, start
return list(range(start, stop, step))
after type Command + p, I got:
start: int, stop: Optional[int], step: int=-1
Does anyone know how to implement this? Thanks so much for any help!
source
share