Skip to content

Commit

Permalink
turtle: various improvements (#3677)
Browse files Browse the repository at this point in the history
* turtle: add None and default value to overloads
* turtle: add default value to write_docstringdict
* turtle: fix _Screen.setup
  • Loading branch information
hauntsaninja authored Jan 29, 2020
1 parent b3a9bfd commit ac234f2
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions stdlib/2and3/turtle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class TurtleScreen(TurtleScreenBase):
def __init__(self, cv: Canvas, mode: str = ..., colormode: float = ..., delay: int = ...) -> None: ...
def clear(self) -> None: ...
@overload
def mode(self) -> str: ...
def mode(self, mode: None = ...) -> str: ...
@overload
def mode(self, mode: str) -> None: ...
def setworldcoordinates(self, llx: float, lly: float, urx: float, ury: float) -> None: ...
def register_shape(self, name: str, shape: Union[_PolygonCoords, Shape, None] = ...) -> None: ...
@overload
def colormode(self) -> float: ...
def colormode(self, cmode: None = ...) -> float: ...
@overload
def colormode(self, cmode: float) -> None: ...
def reset(self) -> None: ...
Expand All @@ -65,11 +65,11 @@ class TurtleScreen(TurtleScreenBase):
@overload
def bgcolor(self, r: float, g: float, b: float) -> None: ...
@overload
def tracer(self) -> int: ...
def tracer(self, n: None = ...) -> int: ...
@overload
def tracer(self, n: int, delay: Optional[int] = ...) -> None: ...
@overload
def delay(self) -> int: ...
def delay(self, delay: None = ...) -> int: ...
@overload
def delay(self, delay: int) -> None: ...
def update(self) -> None: ...
Expand All @@ -82,11 +82,12 @@ class TurtleScreen(TurtleScreenBase):
def listen(self, xdummy: Optional[float] = ..., ydummy: Optional[float] = ...) -> None: ...
def ontimer(self, fun: Callable[[], Any], t: int = ...) -> None: ...
@overload
def bgpic(self) -> str: ...
def bgpic(self, picname: None = ...) -> str: ...
@overload
def bgpic(self, picname: str) -> None: ...
@overload
def screensize(self) -> Tuple[int, int]: ...
def screensize(self, canvwidth: None = ..., canvheight: None = ..., bg: None = ...) -> Tuple[int, int]: ...
# Looks like if self.cv is not a ScrolledCanvas, this could return a tuple as well
@overload
def screensize(self, canvwidth: int, canvheight: int, bg: Optional[_Color] = ...) -> None: ...
onscreenclick = onclick
Expand Down Expand Up @@ -114,18 +115,18 @@ class TNavigator(object):
def xcor(self) -> float: ...
def ycor(self) -> float: ...
@overload
def goto(self, x: Tuple[float, float]) -> None: ...
def goto(self, x: Tuple[float, float], y: None = ...) -> None: ...
@overload
def goto(self, x: float, y: float) -> None: ...
def home(self) -> None: ...
def setx(self, x: float) -> None: ...
def sety(self, y: float) -> None: ...
@overload
def distance(self, x: Union[TNavigator, Tuple[float, float]]) -> float: ...
def distance(self, x: Union[TNavigator, Tuple[float, float]], y: None = ...) -> float: ...
@overload
def distance(self, x: float, y: float) -> float: ...
@overload
def towards(self, x: Union[TNavigator, Tuple[float, float]]) -> float: ...
def towards(self, x: Union[TNavigator, Tuple[float, float]], y: None = ...) -> float: ...
@overload
def towards(self, x: float, y: float) -> float: ...
def heading(self) -> float: ...
Expand All @@ -145,18 +146,18 @@ class TNavigator(object):
class TPen(object):
def __init__(self, resizemode: str = ...) -> None: ...
@overload
def resizemode(self) -> str: ...
def resizemode(self, rmode: None = ...) -> str: ...
@overload
def resizemode(self, rmode: str) -> None: ...
@overload
def pensize(self) -> int: ...
def pensize(self, width: None = ...) -> int: ...
@overload
def pensize(self, width: int) -> None: ...
def penup(self) -> None: ...
def pendown(self) -> None: ...
def isdown(self) -> bool: ...
@overload
def speed(self) -> int: ...
def speed(self, speed: None = ...) -> int: ...
@overload
def speed(self, speed: _Speed) -> None: ...
@overload
Expand Down Expand Up @@ -208,7 +209,7 @@ class RawTurtle(TPen, TNavigator):
def clear(self) -> None: ...
def clone(self: _T) -> _T: ...
@overload
def shape(self) -> str: ...
def shape(self, name: None = ...) -> str: ...
@overload
def shape(self, name: str) -> None: ...
# Unsafely overlaps when no arguments are provided
Expand All @@ -218,7 +219,7 @@ class RawTurtle(TPen, TNavigator):
def shapesize(self, stretch_wid: Optional[float] = ..., stretch_len: Optional[float] = ..., outline: Optional[float] = ...) -> None: ...
if sys.version_info >= (3,):
@overload
def shearfactor(self) -> float: ...
def shearfactor(self, shear: None = ...) -> float: ...
@overload
def shearfactor(self, shear: float) -> None: ...
# Unsafely overlaps when no arguments are provided
Expand All @@ -229,7 +230,7 @@ class RawTurtle(TPen, TNavigator):
def get_shapepoly(self) -> Optional[_PolygonCoords]: ...
def settiltangle(self, angle: float) -> None: ...
@overload
def tiltangle(self) -> float: ...
def tiltangle(self, angle: None = ...) -> float: ...
@overload
def tiltangle(self, angle: float) -> None: ...
def tilt(self, angle: float) -> None: ...
Expand Down Expand Up @@ -258,7 +259,14 @@ class RawTurtle(TPen, TNavigator):

class _Screen(TurtleScreen):
def __init__(self) -> None: ...
def setup(self, width: int = ..., height: int = ..., startx: int = ..., starty: int = ...) -> None: ...
# Note int and float are interpreted differently, hence the Union instead of just float
def setup(
self,
width: Union[int, float] = ...,
height: Union[int, float] = ...,
startx: Optional[int] = ...,
starty: Optional[int] = ...
) -> None: ...
def title(self, titlestring: str) -> None: ...
def bye(self) -> None: ...
def exitonclick(self) -> None: ...
Expand All @@ -271,7 +279,7 @@ class Turtle(RawTurtle):
RawPen = RawTurtle
Pen = Turtle

def write_docstringdict(filename: str) -> None: ...
def write_docstringdict(filename: str = ...) -> None: ...

# Note: it's somewhat unfortunate that we have to copy the function signatures.
# It would be nice if we could partially reduce the redundancy by doing something
Expand All @@ -295,13 +303,13 @@ if sys.version_info >= (3,):

def clear() -> None: ...
@overload
def mode() -> str: ...
def mode(mode: None = ...) -> str: ...
@overload
def mode(mode: str) -> None: ...
def setworldcoordinates(llx: float, lly: float, urx: float, ury: float) -> None: ...
def register_shape(name: str, shape: Union[_PolygonCoords, Shape, None] = ...) -> None: ...
@overload
def colormode() -> float: ...
def colormode(cmode: None = ...) -> float: ...
@overload
def colormode(cmode: float) -> None: ...
def reset() -> None: ...
Expand All @@ -313,11 +321,11 @@ def bgcolor(color: _Color) -> None: ...
@overload
def bgcolor(r: float, g: float, b: float) -> None: ...
@overload
def tracer() -> int: ...
def tracer(n: None = ...) -> int: ...
@overload
def tracer(n: int, delay: Optional[int] = ...) -> None: ...
@overload
def delay() -> int: ...
def delay(delay: None = ...) -> int: ...
@overload
def delay(delay: int) -> None: ...
def update() -> None: ...
Expand All @@ -330,11 +338,11 @@ def onkey(fun: Callable[[], Any], key: str) -> None: ...
def listen(xdummy: Optional[float] = ..., ydummy: Optional[float] = ...) -> None: ...
def ontimer(fun: Callable[[], Any], t: int = ...) -> None: ...
@overload
def bgpic() -> str: ...
def bgpic(picname: None = ...) -> str: ...
@overload
def bgpic(picname: str) -> None: ...
@overload
def screensize() -> Tuple[int, int]: ...
def screensize(canvwidth: None = ..., canvheight: None = ..., bg: None = ...) -> Tuple[int, int]: ...
@overload
def screensize(canvwidth: int, canvheight: int, bg: Optional[_Color] = ...) -> None: ...
onscreenclick = onclick
Expand All @@ -357,18 +365,18 @@ def pos() -> Vec2D: ...
def xcor() -> float: ...
def ycor() -> float: ...
@overload
def goto(x: Tuple[float, float]) -> None: ...
def goto(x: Tuple[float, float], y: None = ...) -> None: ...
@overload
def goto(x: float, y: float) -> None: ...
def home() -> None: ...
def setx(x: float) -> None: ...
def sety(y: float) -> None: ...
@overload
def distance(x: Union[TNavigator, Tuple[float, float]]) -> float: ...
def distance(x: Union[TNavigator, Tuple[float, float]], y: None = ...) -> float: ...
@overload
def distance(x: float, y: float) -> float: ...
@overload
def towards(x: Union[TNavigator, Tuple[float, float]]) -> float: ...
def towards(x: Union[TNavigator, Tuple[float, float]], y: None = ...) -> float: ...
@overload
def towards(x: float, y: float) -> float: ...
def heading() -> float: ...
Expand All @@ -387,18 +395,18 @@ seth = setheading
# Functions copied from TPen:

@overload
def resizemode() -> str: ...
def resizemode(rmode: None = ...) -> str: ...
@overload
def resizemode(rmode: str) -> None: ...
@overload
def pensize() -> int: ...
def pensize(width: None = ...) -> int: ...
@overload
def pensize(width: int) -> None: ...
def penup() -> None: ...
def pendown() -> None: ...
def isdown() -> bool: ...
@overload
def speed() -> int: ...
def speed(speed: None = ...) -> int: ...
@overload
def speed(speed: _Speed) -> None: ...
@overload
Expand Down Expand Up @@ -445,7 +453,7 @@ ht = hideturtle
def setundobuffer(size: Optional[int]) -> None: ...
def undobufferentries() -> int: ...
@overload
def shape() -> str: ...
def shape(name: None = ...) -> str: ...
@overload
def shape(name: str) -> None: ...
# Unsafely overlaps when no arguments are provided
Expand All @@ -455,7 +463,7 @@ def shapesize() -> Tuple[float, float, float]: ... # type: ignore
def shapesize(stretch_wid: Optional[float] = ..., stretch_len: Optional[float] = ..., outline: Optional[float] = ...) -> None: ...
if sys.version_info >= (3,):
@overload
def shearfactor() -> float: ...
def shearfactor(shear: None = ...) -> float: ...
@overload
def shearfactor(shear: float) -> None: ...
# Unsafely overlaps when no arguments are provided
Expand All @@ -466,7 +474,7 @@ if sys.version_info >= (3,):
def get_shapepoly() -> Optional[_PolygonCoords]: ...
def settiltangle(angle: float) -> None: ...
@overload
def tiltangle() -> float: ...
def tiltangle(angle: None = ...) -> float: ...
@overload
def tiltangle(angle: float) -> None: ...
def tilt(angle: float) -> None: ...
Expand Down

0 comments on commit ac234f2

Please sign in to comment.