Use PEP 585 syntax in Python 2, protobuf & _ast stubs, where possible (#6949)

This commit is contained in:
Alex Waygood
2022-01-18 15:14:03 +00:00
committed by GitHub
parent aa885ecd65
commit 8af5e0d340
264 changed files with 2217 additions and 2411 deletions

View File

@@ -1,5 +1,5 @@
from _typeshed import Self
from typing import Any, Callable, Dict, List, Sequence, Text, Tuple, Union, overload
from typing import Any, Callable, Sequence, Text, Union, overload
# TODO: Replace these aliases once we have Python 2 stubs for the Tkinter module.
Canvas = Any
@@ -9,18 +9,18 @@ PhotoImage = Any
# alias we use for return types. Really, these two aliases should be the
# same, but as per the "no union returns" typeshed policy, we'll return
# Any instead.
_Color = Union[Text, Tuple[float, float, float]]
_Color = Union[Text, tuple[float, float, float]]
_AnyColor = Any
# TODO: Replace this with a TypedDict once it becomes standardized.
_PenState = Dict[str, Any]
_PenState = dict[str, Any]
_Speed = Union[str, float]
_PolygonCoords = Sequence[Tuple[float, float]]
_PolygonCoords = Sequence[tuple[float, float]]
# TODO: Type this more accurately
# Vec2D is actually a custom subclass of 'tuple'.
Vec2D = Tuple[float, float]
Vec2D = tuple[float, float]
class TurtleScreenBase(object):
cv: Canvas = ...
@@ -51,7 +51,7 @@ class TurtleScreen(TurtleScreenBase):
@overload
def colormode(self, cmode: float) -> None: ...
def reset(self) -> None: ...
def turtles(self) -> List[Turtle]: ...
def turtles(self) -> list[Turtle]: ...
@overload
def bgcolor(self) -> _AnyColor: ...
@overload
@@ -70,7 +70,7 @@ class TurtleScreen(TurtleScreenBase):
def window_width(self) -> int: ...
def window_height(self) -> int: ...
def getcanvas(self) -> Canvas: ...
def getshapes(self) -> List[str]: ...
def getshapes(self) -> list[str]: ...
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: float | None = ..., ydummy: float | None = ...) -> None: ...
@@ -80,7 +80,7 @@ class TurtleScreen(TurtleScreenBase):
@overload
def bgpic(self, picname: str) -> None: ...
@overload
def screensize(self, canvwidth: None = ..., canvheight: None = ..., bg: None = ...) -> 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: _Color | None = ...) -> None: ...
@@ -90,7 +90,7 @@ class TurtleScreen(TurtleScreenBase):
addshape = register_shape
class TNavigator(object):
START_ORIENTATION: Dict[str, Vec2D] = ...
START_ORIENTATION: dict[str, Vec2D] = ...
DEFAULT_MODE: str = ...
DEFAULT_ANGLEOFFSET: int = ...
DEFAULT_ANGLEORIENT: int = ...
@@ -106,18 +106,18 @@ class TNavigator(object):
def xcor(self) -> float: ...
def ycor(self) -> float: ...
@overload
def goto(self, x: Tuple[float, float], y: None = ...) -> 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: 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: 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: ...
@@ -163,7 +163,7 @@ class TPen(object):
@overload
def fillcolor(self, r: float, g: float, b: float) -> None: ...
@overload
def color(self) -> Tuple[_AnyColor, _AnyColor]: ...
def color(self) -> tuple[_AnyColor, _AnyColor]: ...
@overload
def color(self, color: _Color) -> None: ...
@overload
@@ -188,7 +188,7 @@ class TPen(object):
pensize: int = ...,
speed: int = ...,
resizemode: str = ...,
stretchfactor: Tuple[float, float] = ...,
stretchfactor: tuple[float, float] = ...,
outline: int = ...,
tilt: float = ...,
) -> None: ...
@@ -215,7 +215,7 @@ class RawTurtle(TPen, TNavigator):
def shape(self, name: str) -> None: ...
# Unsafely overlaps when no arguments are provided
@overload
def shapesize(self) -> Tuple[float, float, float]: ... # type: ignore
def shapesize(self) -> tuple[float, float, float]: ... # type: ignore
@overload
def shapesize(
self, stretch_wid: float | None = ..., stretch_len: float | None = ..., outline: float | None = ...
@@ -230,13 +230,13 @@ 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: int | Tuple[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: int | None = ..., *color: _Color) -> None: ...
def write(self, arg: object, move: bool = ..., align: str = ..., font: Tuple[str, int, str] = ...) -> 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) -> _PolygonCoords | None: ...
@@ -296,7 +296,7 @@ def colormode(cmode: None = ...) -> float: ...
@overload
def colormode(cmode: float) -> None: ...
def reset() -> None: ...
def turtles() -> List[Turtle]: ...
def turtles() -> list[Turtle]: ...
@overload
def bgcolor() -> _AnyColor: ...
@overload
@@ -315,7 +315,7 @@ def update() -> None: ...
def window_width() -> int: ...
def window_height() -> int: ...
def getcanvas() -> Canvas: ...
def getshapes() -> List[str]: ...
def getshapes() -> list[str]: ...
def onclick(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ...
def onkey(fun: Callable[[], Any], key: str) -> None: ...
def listen(xdummy: float | None = ..., ydummy: float | None = ...) -> None: ...
@@ -325,7 +325,7 @@ def bgpic(picname: None = ...) -> str: ...
@overload
def bgpic(picname: str) -> None: ...
@overload
def screensize(canvwidth: None = ..., canvheight: None = ..., bg: None = ...) -> Tuple[int, int]: ...
def screensize(canvwidth: None = ..., canvheight: None = ..., bg: None = ...) -> tuple[int, int]: ...
@overload
def screensize(canvwidth: int, canvheight: int, bg: _Color | None = ...) -> None: ...
@@ -353,18 +353,18 @@ def pos() -> Vec2D: ...
def xcor() -> float: ...
def ycor() -> float: ...
@overload
def goto(x: Tuple[float, float], y: None = ...) -> 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: 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: 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: ...
@@ -410,7 +410,7 @@ def fillcolor(color: _Color) -> None: ...
@overload
def fillcolor(r: float, g: float, b: float) -> None: ...
@overload
def color() -> Tuple[_AnyColor, _AnyColor]: ...
def color() -> tuple[_AnyColor, _AnyColor]: ...
@overload
def color(color: _Color) -> None: ...
@overload
@@ -435,7 +435,7 @@ def pen(
pensize: int = ...,
speed: int = ...,
resizemode: str = ...,
stretchfactor: Tuple[float, float] = ...,
stretchfactor: tuple[float, float] = ...,
outline: int = ...,
tilt: float = ...,
) -> None: ...
@@ -459,7 +459,7 @@ def shape(name: str) -> None: ...
# Unsafely overlaps when no arguments are provided
@overload
def shapesize() -> Tuple[float, float, float]: ... # type: ignore
def shapesize() -> tuple[float, float, float]: ... # type: ignore
@overload
def shapesize(stretch_wid: float | None = ..., stretch_len: float | None = ..., outline: float | None = ...) -> None: ...
def settiltangle(angle: float) -> None: ...
@@ -473,13 +473,13 @@ 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: int | Tuple[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: int | None = ..., *color: _Color) -> None: ...
def write(arg: object, move: bool = ..., align: str = ..., font: Tuple[str, int, str] = ...) -> 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() -> _PolygonCoords | None: ...