Switch to PEP-604 syntax in python2 stubs (#5915)

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
This commit is contained in:
Oleg Höfling
2021-08-14 11:12:30 +02:00
committed by GitHub
parent 431c4f7fc1
commit ff63953188
235 changed files with 2473 additions and 2768 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, Callable, Dict, List, Optional, Sequence, Text, Tuple, TypeVar, Union, overload
from typing import Any, Callable, Dict, List, Sequence, Text, Tuple, TypeVar, Union, overload
# TODO: Replace these aliases once we have Python 2 stubs for the Tkinter module.
Canvas = Any
@@ -33,8 +33,8 @@ class Terminator(Exception): ...
class TurtleGraphicsError(Exception): ...
class Shape(object):
def __init__(self, type_: str, data: Union[_PolygonCoords, PhotoImage, None] = ...) -> None: ...
def addcomponent(self, poly: _PolygonCoords, fill: _Color, outline: Optional[_Color] = ...) -> None: ...
def __init__(self, type_: str, data: _PolygonCoords | PhotoImage | None = ...) -> None: ...
def addcomponent(self, poly: _PolygonCoords, fill: _Color, outline: _Color | None = ...) -> None: ...
class TurtleScreen(TurtleScreenBase):
def __init__(self, cv: Canvas, mode: str = ..., colormode: float = ..., delay: int = ...) -> None: ...
@@ -44,7 +44,7 @@ class TurtleScreen(TurtleScreenBase):
@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: ...
def register_shape(self, name: str, shape: _PolygonCoords | Shape | None = ...) -> None: ...
@overload
def colormode(self, cmode: None = ...) -> float: ...
@overload
@@ -60,7 +60,7 @@ class TurtleScreen(TurtleScreenBase):
@overload
def tracer(self, n: None = ...) -> int: ...
@overload
def tracer(self, n: int, delay: Optional[int] = ...) -> None: ...
def tracer(self, n: int, delay: int | None = ...) -> None: ...
@overload
def delay(self, delay: None = ...) -> int: ...
@overload
@@ -70,9 +70,9 @@ class TurtleScreen(TurtleScreenBase):
def window_height(self) -> int: ...
def getcanvas(self) -> Canvas: ...
def getshapes(self) -> List[str]: ...
def onclick(self, fun: Callable[[float, float], Any], btn: int = ..., add: Optional[Any] = ...) -> None: ...
def onclick(self, fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ...
def onkey(self, fun: Callable[[], Any], key: str) -> None: ...
def listen(self, xdummy: Optional[float] = ..., ydummy: Optional[float] = ...) -> None: ...
def listen(self, xdummy: float | None = ..., ydummy: float | None = ...) -> None: ...
def ontimer(self, fun: Callable[[], Any], t: int = ...) -> None: ...
@overload
def bgpic(self, picname: None = ...) -> str: ...
@@ -82,7 +82,7 @@ class TurtleScreen(TurtleScreenBase):
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: ...
def screensize(self, canvwidth: int, canvheight: int, bg: _Color | None = ...) -> None: ...
onscreenclick = onclick
resetscreen = reset
clearscreen = clear
@@ -112,16 +112,16 @@ class TNavigator(object):
def setx(self, x: float) -> None: ...
def sety(self, y: float) -> None: ...
@overload
def distance(self, x: Union[TNavigator, Tuple[float, float]], y: None = ...) -> float: ...
def distance(self, x: 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]], y: None = ...) -> float: ...
def towards(self, x: TNavigator | Tuple[float, float], y: None = ...) -> float: ...
@overload
def towards(self, x: float, y: float) -> float: ...
def heading(self) -> float: ...
def setheading(self, to_angle: float) -> None: ...
def circle(self, radius: float, extent: Optional[float] = ..., steps: Optional[int] = ...) -> None: ...
def circle(self, radius: float, extent: float | None = ..., steps: int | None = ...) -> None: ...
fd = forward
bk = back
backward = back
@@ -178,7 +178,7 @@ class TPen(object):
@overload
def pen(
self,
pen: Optional[_PenState] = ...,
pen: _PenState | None = ...,
*,
shown: bool = ...,
pendown: bool = ...,
@@ -203,10 +203,10 @@ _T = TypeVar("_T")
class RawTurtle(TPen, TNavigator):
def __init__(
self, canvas: Union[Canvas, TurtleScreen, None] = ..., shape: str = ..., undobuffersize: int = ..., visible: bool = ...
self, canvas: Canvas | TurtleScreen | None = ..., shape: str = ..., undobuffersize: int = ..., visible: bool = ...
) -> None: ...
def reset(self) -> None: ...
def setundobuffer(self, size: Optional[int]) -> None: ...
def setundobuffer(self, size: int | None) -> None: ...
def undobufferentries(self) -> int: ...
def clear(self) -> None: ...
def clone(self: _T) -> _T: ...
@@ -219,7 +219,7 @@ class RawTurtle(TPen, TNavigator):
def shapesize(self) -> Tuple[float, float, float]: ... # type: ignore
@overload
def shapesize(
self, stretch_wid: Optional[float] = ..., stretch_len: Optional[float] = ..., outline: Optional[float] = ...
self, stretch_wid: float | None = ..., stretch_len: float | None = ..., outline: float | None = ...
) -> None: ...
def settiltangle(self, angle: float) -> None: ...
@overload
@@ -231,22 +231,22 @@ class RawTurtle(TPen, TNavigator):
# a compound stamp or not. So, as per the "no Union return" policy,
# we return Any.
def stamp(self) -> Any: ...
def clearstamp(self, stampid: Union[int, Tuple[int, ...]]) -> None: ...
def clearstamps(self, n: Optional[int] = ...) -> None: ...
def clearstamp(self, stampid: int | Tuple[int, ...]) -> None: ...
def clearstamps(self, n: int | None = ...) -> None: ...
def filling(self) -> bool: ...
def begin_fill(self) -> None: ...
def end_fill(self) -> None: ...
def dot(self, size: Optional[int] = ..., *color: _Color) -> None: ...
def dot(self, size: int | None = ..., *color: _Color) -> None: ...
def write(self, arg: object, move: bool = ..., align: str = ..., font: Tuple[str, int, str] = ...) -> None: ...
def begin_poly(self) -> None: ...
def end_poly(self) -> None: ...
def get_poly(self) -> Optional[_PolygonCoords]: ...
def get_poly(self) -> _PolygonCoords | None: ...
def getscreen(self) -> TurtleScreen: ...
def getturtle(self: _T) -> _T: ...
getpen = getturtle
def onclick(self, fun: Callable[[float, float], Any], btn: int = ..., add: Optional[bool] = ...) -> None: ...
def onrelease(self, fun: Callable[[float, float], Any], btn: int = ..., add: Optional[bool] = ...) -> None: ...
def ondrag(self, fun: Callable[[float, float], Any], btn: int = ..., add: Optional[bool] = ...) -> None: ...
def onclick(self, fun: Callable[[float, float], Any], btn: int = ..., add: bool | None = ...) -> None: ...
def onrelease(self, fun: Callable[[float, float], Any], btn: int = ..., add: bool | None = ...) -> None: ...
def ondrag(self, fun: Callable[[float, float], Any], btn: int = ..., add: bool | None = ...) -> None: ...
def undo(self) -> None: ...
turtlesize = shapesize
@@ -254,11 +254,7 @@ class _Screen(TurtleScreen):
def __init__(self) -> 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] = ...,
self, width: int | float = ..., height: int | float = ..., startx: int | None = ..., starty: int | None = ...
) -> None: ...
def title(self, titlestring: str) -> None: ...
def bye(self) -> None: ...
@@ -295,7 +291,7 @@ 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: ...
def register_shape(name: str, shape: _PolygonCoords | Shape | None = ...) -> None: ...
@overload
def colormode(cmode: None = ...) -> float: ...
@overload
@@ -311,7 +307,7 @@ def bgcolor(r: float, g: float, b: float) -> None: ...
@overload
def tracer(n: None = ...) -> int: ...
@overload
def tracer(n: int, delay: Optional[int] = ...) -> None: ...
def tracer(n: int, delay: int | None = ...) -> None: ...
@overload
def delay(delay: None = ...) -> int: ...
@overload
@@ -321,9 +317,9 @@ def window_width() -> int: ...
def window_height() -> int: ...
def getcanvas() -> Canvas: ...
def getshapes() -> List[str]: ...
def onclick(fun: Callable[[float, float], Any], btn: int = ..., add: Optional[Any] = ...) -> None: ...
def onclick(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ...
def onkey(fun: Callable[[], Any], key: str) -> None: ...
def listen(xdummy: Optional[float] = ..., ydummy: Optional[float] = ...) -> None: ...
def listen(xdummy: float | None = ..., ydummy: float | None = ...) -> None: ...
def ontimer(fun: Callable[[], Any], t: int = ...) -> None: ...
@overload
def bgpic(picname: None = ...) -> str: ...
@@ -332,7 +328,7 @@ def bgpic(picname: str) -> None: ...
@overload
def screensize(canvwidth: None = ..., canvheight: None = ..., bg: None = ...) -> Tuple[int, int]: ...
@overload
def screensize(canvwidth: int, canvheight: int, bg: Optional[_Color] = ...) -> None: ...
def screensize(canvwidth: int, canvheight: int, bg: _Color | None = ...) -> None: ...
onscreenclick = onclick
resetscreen = reset
@@ -340,7 +336,7 @@ clearscreen = clear
addshape = register_shape
# Functions copied from _Screen:
def setup(width: float = ..., height: float = ..., startx: Optional[int] = ..., starty: Optional[int] = ...) -> None: ...
def setup(width: float = ..., height: float = ..., startx: int | None = ..., starty: int | None = ...) -> None: ...
def title(titlestring: str) -> None: ...
def bye() -> None: ...
def exitonclick() -> None: ...
@@ -365,16 +361,16 @@ def home() -> None: ...
def setx(x: float) -> None: ...
def sety(y: float) -> None: ...
@overload
def distance(x: Union[TNavigator, Tuple[float, float]], y: None = ...) -> float: ...
def distance(x: TNavigator | Tuple[float, float], y: None = ...) -> float: ...
@overload
def distance(x: float, y: float) -> float: ...
@overload
def towards(x: Union[TNavigator, Tuple[float, float]], y: None = ...) -> float: ...
def towards(x: TNavigator | Tuple[float, float], y: None = ...) -> float: ...
@overload
def towards(x: float, y: float) -> float: ...
def heading() -> float: ...
def setheading(to_angle: float) -> None: ...
def circle(radius: float, extent: Optional[float] = ..., steps: Optional[int] = ...) -> None: ...
def circle(radius: float, extent: float | None = ..., steps: int | None = ...) -> None: ...
fd = forward
bk = back
@@ -431,7 +427,7 @@ def isvisible() -> bool: ...
def pen() -> _PenState: ... # type: ignore
@overload
def pen(
pen: Optional[_PenState] = ...,
pen: _PenState | None = ...,
*,
shown: bool = ...,
pendown: bool = ...,
@@ -455,7 +451,7 @@ ht = hideturtle
# Functions copied from RawTurtle:
def setundobuffer(size: Optional[int]) -> None: ...
def setundobuffer(size: int | None) -> None: ...
def undobufferentries() -> int: ...
@overload
def shape(name: None = ...) -> str: ...
@@ -466,7 +462,7 @@ def shape(name: str) -> None: ...
@overload
def shapesize() -> Tuple[float, float, float]: ... # type: ignore
@overload
def shapesize(stretch_wid: Optional[float] = ..., stretch_len: Optional[float] = ..., outline: Optional[float] = ...) -> None: ...
def shapesize(stretch_wid: float | None = ..., stretch_len: float | None = ..., outline: float | None = ...) -> None: ...
def settiltangle(angle: float) -> None: ...
@overload
def tiltangle(angle: None = ...) -> float: ...
@@ -478,23 +474,23 @@ def tilt(angle: float) -> None: ...
# a compound stamp or not. So, as per the "no Union return" policy,
# we return Any.
def stamp() -> Any: ...
def clearstamp(stampid: Union[int, Tuple[int, ...]]) -> None: ...
def clearstamps(n: Optional[int] = ...) -> None: ...
def clearstamp(stampid: int | Tuple[int, ...]) -> None: ...
def clearstamps(n: int | None = ...) -> None: ...
def filling() -> bool: ...
def begin_fill() -> None: ...
def end_fill() -> None: ...
def dot(size: Optional[int] = ..., *color: _Color) -> None: ...
def dot(size: int | None = ..., *color: _Color) -> None: ...
def write(arg: object, move: bool = ..., align: str = ..., font: Tuple[str, int, str] = ...) -> None: ...
def begin_poly() -> None: ...
def end_poly() -> None: ...
def get_poly() -> Optional[_PolygonCoords]: ...
def get_poly() -> _PolygonCoords | None: ...
def getscreen() -> TurtleScreen: ...
def getturtle() -> Turtle: ...
getpen = getturtle
def onrelease(fun: Callable[[float, float], Any], btn: int = ..., add: Optional[Any] = ...) -> None: ...
def ondrag(fun: Callable[[float, float], Any], btn: int = ..., add: Optional[Any] = ...) -> None: ...
def onrelease(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ...
def ondrag(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ...
def undo() -> None: ...
turtlesize = shapesize