mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
Big diff: Use new "|" union syntax (#5872)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from tkinter import Canvas, PhotoImage
|
||||
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, TypeVar, Union, overload
|
||||
from typing import Any, Callable, Dict, List, Sequence, Tuple, TypeVar, Union, overload
|
||||
|
||||
# Note: '_Color' is the alias we use for arguments and _AnyColor is the
|
||||
# alias we use for return types. Really, these two aliases should be the
|
||||
@@ -26,22 +26,17 @@ class TurtleScreenBase(object):
|
||||
yscale: float = ...
|
||||
def __init__(self, cv: Canvas) -> None: ...
|
||||
def mainloop(self) -> None: ...
|
||||
def textinput(self, title: str, prompt: str) -> Optional[str]: ...
|
||||
def textinput(self, title: str, prompt: str) -> str | None: ...
|
||||
def numinput(
|
||||
self,
|
||||
title: str,
|
||||
prompt: str,
|
||||
default: Optional[float] = ...,
|
||||
minval: Optional[float] = ...,
|
||||
maxval: Optional[float] = ...,
|
||||
) -> Optional[float]: ...
|
||||
self, title: str, prompt: str, default: float | None = ..., minval: float | None = ..., maxval: float | None = ...
|
||||
) -> float | None: ...
|
||||
|
||||
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: ...
|
||||
@@ -51,7 +46,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
|
||||
@@ -67,7 +62,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
|
||||
@@ -77,9 +72,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: ...
|
||||
@@ -89,12 +84,12 @@ 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
|
||||
addshape = register_shape
|
||||
def onkeypress(self, fun: Callable[[], Any], key: Optional[str] = ...) -> None: ...
|
||||
def onkeypress(self, fun: Callable[[], Any], key: str | None = ...) -> None: ...
|
||||
onkeyrelease = onkey
|
||||
|
||||
class TNavigator(object):
|
||||
@@ -121,16 +116,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
|
||||
@@ -187,7 +182,7 @@ class TPen(object):
|
||||
@overload
|
||||
def pen(
|
||||
self,
|
||||
pen: Optional[_PenState] = ...,
|
||||
pen: _PenState | None = ...,
|
||||
*,
|
||||
shown: bool = ...,
|
||||
pendown: bool = ...,
|
||||
@@ -212,10 +207,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: ...
|
||||
@@ -228,7 +223,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: ...
|
||||
@overload
|
||||
def shearfactor(self, shear: None = ...) -> float: ...
|
||||
@@ -239,9 +234,9 @@ class RawTurtle(TPen, TNavigator):
|
||||
def shapetransform(self) -> Tuple[float, float, float, float]: ... # type: ignore
|
||||
@overload
|
||||
def shapetransform(
|
||||
self, t11: Optional[float] = ..., t12: Optional[float] = ..., t21: Optional[float] = ..., t22: Optional[float] = ...
|
||||
self, t11: float | None = ..., t12: float | None = ..., t21: float | None = ..., t22: float | None = ...
|
||||
) -> None: ...
|
||||
def get_shapepoly(self) -> Optional[_PolygonCoords]: ...
|
||||
def get_shapepoly(self) -> _PolygonCoords | None: ...
|
||||
def settiltangle(self, angle: float) -> None: ...
|
||||
@overload
|
||||
def tiltangle(self, angle: None = ...) -> float: ...
|
||||
@@ -252,22 +247,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
|
||||
|
||||
@@ -275,11 +270,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: ...
|
||||
@@ -307,10 +298,10 @@ def write_docstringdict(filename: str = ...) -> None: ...
|
||||
# Note: mainloop() was always present in the global scope, but was added to
|
||||
# TurtleScreenBase in Python 3.0
|
||||
def mainloop() -> None: ...
|
||||
def textinput(title: str, prompt: str) -> Optional[str]: ...
|
||||
def textinput(title: str, prompt: str) -> str | None: ...
|
||||
def numinput(
|
||||
title: str, prompt: str, default: Optional[float] = ..., minval: Optional[float] = ..., maxval: Optional[float] = ...
|
||||
) -> Optional[float]: ...
|
||||
title: str, prompt: str, default: float | None = ..., minval: float | None = ..., maxval: float | None = ...
|
||||
) -> float | None: ...
|
||||
|
||||
# Functions copied from TurtleScreen:
|
||||
|
||||
@@ -320,7 +311,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
|
||||
@@ -336,7 +327,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
|
||||
@@ -346,9 +337,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: ...
|
||||
@@ -357,20 +348,20 @@ 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
|
||||
clearscreen = clear
|
||||
addshape = register_shape
|
||||
|
||||
def onkeypress(fun: Callable[[], Any], key: Optional[str] = ...) -> None: ...
|
||||
def onkeypress(fun: Callable[[], Any], key: str | None = ...) -> None: ...
|
||||
|
||||
onkeyrelease = onkey
|
||||
|
||||
# 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: ...
|
||||
@@ -395,16 +386,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
|
||||
@@ -461,7 +452,7 @@ def isvisible() -> bool: ...
|
||||
def pen() -> _PenState: ... # type: ignore
|
||||
@overload
|
||||
def pen(
|
||||
pen: Optional[_PenState] = ...,
|
||||
pen: _PenState | None = ...,
|
||||
*,
|
||||
shown: bool = ...,
|
||||
pendown: bool = ...,
|
||||
@@ -485,7 +476,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: ...
|
||||
@@ -496,7 +487,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: ...
|
||||
@overload
|
||||
def shearfactor(shear: None = ...) -> float: ...
|
||||
@overload
|
||||
@@ -507,9 +498,9 @@ def shearfactor(shear: float) -> None: ...
|
||||
def shapetransform() -> Tuple[float, float, float, float]: ... # type: ignore
|
||||
@overload
|
||||
def shapetransform(
|
||||
t11: Optional[float] = ..., t12: Optional[float] = ..., t21: Optional[float] = ..., t22: Optional[float] = ...
|
||||
t11: float | None = ..., t12: float | None = ..., t21: float | None = ..., t22: float | None = ...
|
||||
) -> None: ...
|
||||
def get_shapepoly() -> Optional[_PolygonCoords]: ...
|
||||
def get_shapepoly() -> _PolygonCoords | None: ...
|
||||
def settiltangle(angle: float) -> None: ...
|
||||
@overload
|
||||
def tiltangle(angle: None = ...) -> float: ...
|
||||
@@ -521,23 +512,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
|
||||
|
||||
Reference in New Issue
Block a user