massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / turtle.pyi
1 from tkinter import Canvas, PhotoImage
2 from typing import Any, Callable, Dict, Sequence, Tuple, TypeVar, Union, overload
3
4 # Note: '_Color' is the alias we use for arguments and _AnyColor is the
5 # alias we use for return types. Really, these two aliases should be the
6 # same, but as per the "no union returns" typeshed policy, we'll return
7 # Any instead.
8 _Color = Union[str, Tuple[float, float, float]]
9 _AnyColor = Any
10
11 # TODO: Replace this with a TypedDict once it becomes standardized.
12 _PenState = Dict[str, Any]
13
14 _Speed = Union[str, float]
15 _PolygonCoords = Sequence[Tuple[float, float]]
16
17 # TODO: Type this more accurately
18 # Vec2D is actually a custom subclass of 'tuple'.
19 Vec2D = Tuple[float, float]
20
21 class TurtleScreenBase(object):
22     cv: Canvas
23     canvwidth: int
24     canvheight: int
25     xscale: float
26     yscale: float
27     def __init__(self, cv: Canvas) -> None: ...
28     def mainloop(self) -> None: ...
29     def textinput(self, title: str, prompt: str) -> str | None: ...
30     def numinput(
31         self, title: str, prompt: str, default: float | None = ..., minval: float | None = ..., maxval: float | None = ...
32     ) -> float | None: ...
33
34 class Terminator(Exception): ...
35 class TurtleGraphicsError(Exception): ...
36
37 class Shape(object):
38     def __init__(self, type_: str, data: _PolygonCoords | PhotoImage | None = ...) -> None: ...
39     def addcomponent(self, poly: _PolygonCoords, fill: _Color, outline: _Color | None = ...) -> None: ...
40
41 class TurtleScreen(TurtleScreenBase):
42     def __init__(self, cv: Canvas, mode: str = ..., colormode: float = ..., delay: int = ...) -> None: ...
43     def clear(self) -> None: ...
44     @overload
45     def mode(self, mode: None = ...) -> str: ...
46     @overload
47     def mode(self, mode: str) -> None: ...
48     def setworldcoordinates(self, llx: float, lly: float, urx: float, ury: float) -> None: ...
49     def register_shape(self, name: str, shape: _PolygonCoords | Shape | None = ...) -> None: ...
50     @overload
51     def colormode(self, cmode: None = ...) -> float: ...
52     @overload
53     def colormode(self, cmode: float) -> None: ...
54     def reset(self) -> None: ...
55     def turtles(self) -> list[Turtle]: ...
56     @overload
57     def bgcolor(self) -> _AnyColor: ...
58     @overload
59     def bgcolor(self, color: _Color) -> None: ...
60     @overload
61     def bgcolor(self, r: float, g: float, b: float) -> None: ...
62     @overload
63     def tracer(self, n: None = ...) -> int: ...
64     @overload
65     def tracer(self, n: int, delay: int | None = ...) -> None: ...
66     @overload
67     def delay(self, delay: None = ...) -> int: ...
68     @overload
69     def delay(self, delay: int) -> None: ...
70     def update(self) -> None: ...
71     def window_width(self) -> int: ...
72     def window_height(self) -> int: ...
73     def getcanvas(self) -> Canvas: ...
74     def getshapes(self) -> list[str]: ...
75     def onclick(self, fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ...
76     def onkey(self, fun: Callable[[], Any], key: str) -> None: ...
77     def listen(self, xdummy: float | None = ..., ydummy: float | None = ...) -> None: ...
78     def ontimer(self, fun: Callable[[], Any], t: int = ...) -> None: ...
79     @overload
80     def bgpic(self, picname: None = ...) -> str: ...
81     @overload
82     def bgpic(self, picname: str) -> None: ...
83     @overload
84     def screensize(self, canvwidth: None = ..., canvheight: None = ..., bg: None = ...) -> tuple[int, int]: ...
85     # Looks like if self.cv is not a ScrolledCanvas, this could return a tuple as well
86     @overload
87     def screensize(self, canvwidth: int, canvheight: int, bg: _Color | None = ...) -> None: ...
88     onscreenclick = onclick
89     resetscreen = reset
90     clearscreen = clear
91     addshape = register_shape
92     def onkeypress(self, fun: Callable[[], Any], key: str | None = ...) -> None: ...
93     onkeyrelease = onkey
94
95 class TNavigator(object):
96     START_ORIENTATION: dict[str, Vec2D]
97     DEFAULT_MODE: str
98     DEFAULT_ANGLEOFFSET: int
99     DEFAULT_ANGLEORIENT: int
100     def __init__(self, mode: str = ...) -> None: ...
101     def reset(self) -> None: ...
102     def degrees(self, fullcircle: float = ...) -> None: ...
103     def radians(self) -> None: ...
104     def forward(self, distance: float) -> None: ...
105     def back(self, distance: float) -> None: ...
106     def right(self, angle: float) -> None: ...
107     def left(self, angle: float) -> None: ...
108     def pos(self) -> Vec2D: ...
109     def xcor(self) -> float: ...
110     def ycor(self) -> float: ...
111     @overload
112     def goto(self, x: tuple[float, float], y: None = ...) -> None: ...
113     @overload
114     def goto(self, x: float, y: float) -> None: ...
115     def home(self) -> None: ...
116     def setx(self, x: float) -> None: ...
117     def sety(self, y: float) -> None: ...
118     @overload
119     def distance(self, x: TNavigator | tuple[float, float], y: None = ...) -> float: ...
120     @overload
121     def distance(self, x: float, y: float) -> float: ...
122     @overload
123     def towards(self, x: TNavigator | tuple[float, float], y: None = ...) -> float: ...
124     @overload
125     def towards(self, x: float, y: float) -> float: ...
126     def heading(self) -> float: ...
127     def setheading(self, to_angle: float) -> None: ...
128     def circle(self, radius: float, extent: float | None = ..., steps: int | None = ...) -> None: ...
129     fd = forward
130     bk = back
131     backward = back
132     rt = right
133     lt = left
134     position = pos
135     setpos = goto
136     setposition = goto
137     seth = setheading
138
139 class TPen(object):
140     def __init__(self, resizemode: str = ...) -> None: ...
141     @overload
142     def resizemode(self, rmode: None = ...) -> str: ...
143     @overload
144     def resizemode(self, rmode: str) -> None: ...
145     @overload
146     def pensize(self, width: None = ...) -> int: ...
147     @overload
148     def pensize(self, width: int) -> None: ...
149     def penup(self) -> None: ...
150     def pendown(self) -> None: ...
151     def isdown(self) -> bool: ...
152     @overload
153     def speed(self, speed: None = ...) -> int: ...
154     @overload
155     def speed(self, speed: _Speed) -> None: ...
156     @overload
157     def pencolor(self) -> _AnyColor: ...
158     @overload
159     def pencolor(self, color: _Color) -> None: ...
160     @overload
161     def pencolor(self, r: float, g: float, b: float) -> None: ...
162     @overload
163     def fillcolor(self) -> _AnyColor: ...
164     @overload
165     def fillcolor(self, color: _Color) -> None: ...
166     @overload
167     def fillcolor(self, r: float, g: float, b: float) -> None: ...
168     @overload
169     def color(self) -> tuple[_AnyColor, _AnyColor]: ...
170     @overload
171     def color(self, color: _Color) -> None: ...
172     @overload
173     def color(self, r: float, g: float, b: float) -> None: ...
174     @overload
175     def color(self, color1: _Color, color2: _Color) -> None: ...
176     def showturtle(self) -> None: ...
177     def hideturtle(self) -> None: ...
178     def isvisible(self) -> bool: ...
179     # Note: signatures 1 and 2 overlap unsafely when no arguments are provided
180     @overload
181     def pen(self) -> _PenState: ...  # type: ignore
182     @overload
183     def pen(
184         self,
185         pen: _PenState | None = ...,
186         *,
187         shown: bool = ...,
188         pendown: bool = ...,
189         pencolor: _Color = ...,
190         fillcolor: _Color = ...,
191         pensize: int = ...,
192         speed: int = ...,
193         resizemode: str = ...,
194         stretchfactor: tuple[float, float] = ...,
195         outline: int = ...,
196         tilt: float = ...,
197     ) -> None: ...
198     width = pensize
199     up = penup
200     pu = penup
201     pd = pendown
202     down = pendown
203     st = showturtle
204     ht = hideturtle
205
206 _T = TypeVar("_T")
207
208 class RawTurtle(TPen, TNavigator):
209     def __init__(
210         self, canvas: Canvas | TurtleScreen | None = ..., shape: str = ..., undobuffersize: int = ..., visible: bool = ...
211     ) -> None: ...
212     def reset(self) -> None: ...
213     def setundobuffer(self, size: int | None) -> None: ...
214     def undobufferentries(self) -> int: ...
215     def clear(self) -> None: ...
216     def clone(self: _T) -> _T: ...
217     @overload
218     def shape(self, name: None = ...) -> str: ...
219     @overload
220     def shape(self, name: str) -> None: ...
221     # Unsafely overlaps when no arguments are provided
222     @overload
223     def shapesize(self) -> tuple[float, float, float]: ...  # type: ignore
224     @overload
225     def shapesize(
226         self, stretch_wid: float | None = ..., stretch_len: float | None = ..., outline: float | None = ...
227     ) -> None: ...
228     @overload
229     def shearfactor(self, shear: None = ...) -> float: ...
230     @overload
231     def shearfactor(self, shear: float) -> None: ...
232     # Unsafely overlaps when no arguments are provided
233     @overload
234     def shapetransform(self) -> tuple[float, float, float, float]: ...  # type: ignore
235     @overload
236     def shapetransform(
237         self, t11: float | None = ..., t12: float | None = ..., t21: float | None = ..., t22: float | None = ...
238     ) -> None: ...
239     def get_shapepoly(self) -> _PolygonCoords | None: ...
240     def settiltangle(self, angle: float) -> None: ...
241     @overload
242     def tiltangle(self, angle: None = ...) -> float: ...
243     @overload
244     def tiltangle(self, angle: float) -> None: ...
245     def tilt(self, angle: float) -> None: ...
246     # Can return either 'int' or Tuple[int, ...] based on if the stamp is
247     # a compound stamp or not. So, as per the "no Union return" policy,
248     # we return Any.
249     def stamp(self) -> Any: ...
250     def clearstamp(self, stampid: int | Tuple[int, ...]) -> None: ...
251     def clearstamps(self, n: int | None = ...) -> None: ...
252     def filling(self) -> bool: ...
253     def begin_fill(self) -> None: ...
254     def end_fill(self) -> None: ...
255     def dot(self, size: int | None = ..., *color: _Color) -> None: ...
256     def write(self, arg: object, move: bool = ..., align: str = ..., font: tuple[str, int, str] = ...) -> None: ...
257     def begin_poly(self) -> None: ...
258     def end_poly(self) -> None: ...
259     def get_poly(self) -> _PolygonCoords | None: ...
260     def getscreen(self) -> TurtleScreen: ...
261     def getturtle(self: _T) -> _T: ...
262     getpen = getturtle
263     def onclick(self, fun: Callable[[float, float], Any], btn: int = ..., add: bool | None = ...) -> None: ...
264     def onrelease(self, fun: Callable[[float, float], Any], btn: int = ..., add: bool | None = ...) -> None: ...
265     def ondrag(self, fun: Callable[[float, float], Any], btn: int = ..., add: bool | None = ...) -> None: ...
266     def undo(self) -> None: ...
267     turtlesize = shapesize
268
269 class _Screen(TurtleScreen):
270     def __init__(self) -> None: ...
271     # Note int and float are interpreted differently, hence the Union instead of just float
272     def setup(
273         self, width: int | float = ..., height: int | float = ..., startx: int | None = ..., starty: int | None = ...
274     ) -> None: ...
275     def title(self, titlestring: str) -> None: ...
276     def bye(self) -> None: ...
277     def exitonclick(self) -> None: ...
278
279 class Turtle(RawTurtle):
280     def __init__(self, shape: str = ..., undobuffersize: int = ..., visible: bool = ...) -> None: ...
281
282 RawPen = RawTurtle
283 Pen = Turtle
284
285 def write_docstringdict(filename: str = ...) -> None: ...
286
287 # Note: it's somewhat unfortunate that we have to copy the function signatures.
288 # It would be nice if we could partially reduce the redundancy by doing something
289 # like the following:
290 #
291 #     _screen: Screen
292 #     clear = _screen.clear
293 #
294 # However, it seems pytype does not support this type of syntax in pyi files.
295
296 # Functions copied from TurtleScreenBase:
297
298 # Note: mainloop() was always present in the global scope, but was added to
299 # TurtleScreenBase in Python 3.0
300 def mainloop() -> None: ...
301 def textinput(title: str, prompt: str) -> str | None: ...
302 def numinput(
303     title: str, prompt: str, default: float | None = ..., minval: float | None = ..., maxval: float | None = ...
304 ) -> float | None: ...
305
306 # Functions copied from TurtleScreen:
307
308 def clear() -> None: ...
309 @overload
310 def mode(mode: None = ...) -> str: ...
311 @overload
312 def mode(mode: str) -> None: ...
313 def setworldcoordinates(llx: float, lly: float, urx: float, ury: float) -> None: ...
314 def register_shape(name: str, shape: _PolygonCoords | Shape | None = ...) -> None: ...
315 @overload
316 def colormode(cmode: None = ...) -> float: ...
317 @overload
318 def colormode(cmode: float) -> None: ...
319 def reset() -> None: ...
320 def turtles() -> list[Turtle]: ...
321 @overload
322 def bgcolor() -> _AnyColor: ...
323 @overload
324 def bgcolor(color: _Color) -> None: ...
325 @overload
326 def bgcolor(r: float, g: float, b: float) -> None: ...
327 @overload
328 def tracer(n: None = ...) -> int: ...
329 @overload
330 def tracer(n: int, delay: int | None = ...) -> None: ...
331 @overload
332 def delay(delay: None = ...) -> int: ...
333 @overload
334 def delay(delay: int) -> None: ...
335 def update() -> None: ...
336 def window_width() -> int: ...
337 def window_height() -> int: ...
338 def getcanvas() -> Canvas: ...
339 def getshapes() -> list[str]: ...
340 def onclick(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ...
341 def onkey(fun: Callable[[], Any], key: str) -> None: ...
342 def listen(xdummy: float | None = ..., ydummy: float | None = ...) -> None: ...
343 def ontimer(fun: Callable[[], Any], t: int = ...) -> None: ...
344 @overload
345 def bgpic(picname: None = ...) -> str: ...
346 @overload
347 def bgpic(picname: str) -> None: ...
348 @overload
349 def screensize(canvwidth: None = ..., canvheight: None = ..., bg: None = ...) -> tuple[int, int]: ...
350 @overload
351 def screensize(canvwidth: int, canvheight: int, bg: _Color | None = ...) -> None: ...
352
353 onscreenclick = onclick
354 resetscreen = reset
355 clearscreen = clear
356 addshape = register_shape
357
358 def onkeypress(fun: Callable[[], Any], key: str | None = ...) -> None: ...
359
360 onkeyrelease = onkey
361
362 # Functions copied from _Screen:
363
364 def setup(width: float = ..., height: float = ..., startx: int | None = ..., starty: int | None = ...) -> None: ...
365 def title(titlestring: str) -> None: ...
366 def bye() -> None: ...
367 def exitonclick() -> None: ...
368 def Screen() -> _Screen: ...
369
370 # Functions copied from TNavigator:
371
372 def degrees(fullcircle: float = ...) -> None: ...
373 def radians() -> None: ...
374 def forward(distance: float) -> None: ...
375 def back(distance: float) -> None: ...
376 def right(angle: float) -> None: ...
377 def left(angle: float) -> None: ...
378 def pos() -> Vec2D: ...
379 def xcor() -> float: ...
380 def ycor() -> float: ...
381 @overload
382 def goto(x: tuple[float, float], y: None = ...) -> None: ...
383 @overload
384 def goto(x: float, y: float) -> None: ...
385 def home() -> None: ...
386 def setx(x: float) -> None: ...
387 def sety(y: float) -> None: ...
388 @overload
389 def distance(x: TNavigator | tuple[float, float], y: None = ...) -> float: ...
390 @overload
391 def distance(x: float, y: float) -> float: ...
392 @overload
393 def towards(x: TNavigator | tuple[float, float], y: None = ...) -> float: ...
394 @overload
395 def towards(x: float, y: float) -> float: ...
396 def heading() -> float: ...
397 def setheading(to_angle: float) -> None: ...
398 def circle(radius: float, extent: float | None = ..., steps: int | None = ...) -> None: ...
399
400 fd = forward
401 bk = back
402 backward = back
403 rt = right
404 lt = left
405 position = pos
406 setpos = goto
407 setposition = goto
408 seth = setheading
409
410 # Functions copied from TPen:
411 @overload
412 def resizemode(rmode: None = ...) -> str: ...
413 @overload
414 def resizemode(rmode: str) -> None: ...
415 @overload
416 def pensize(width: None = ...) -> int: ...
417 @overload
418 def pensize(width: int) -> None: ...
419 def penup() -> None: ...
420 def pendown() -> None: ...
421 def isdown() -> bool: ...
422 @overload
423 def speed(speed: None = ...) -> int: ...
424 @overload
425 def speed(speed: _Speed) -> None: ...
426 @overload
427 def pencolor() -> _AnyColor: ...
428 @overload
429 def pencolor(color: _Color) -> None: ...
430 @overload
431 def pencolor(r: float, g: float, b: float) -> None: ...
432 @overload
433 def fillcolor() -> _AnyColor: ...
434 @overload
435 def fillcolor(color: _Color) -> None: ...
436 @overload
437 def fillcolor(r: float, g: float, b: float) -> None: ...
438 @overload
439 def color() -> tuple[_AnyColor, _AnyColor]: ...
440 @overload
441 def color(color: _Color) -> None: ...
442 @overload
443 def color(r: float, g: float, b: float) -> None: ...
444 @overload
445 def color(color1: _Color, color2: _Color) -> None: ...
446 def showturtle() -> None: ...
447 def hideturtle() -> None: ...
448 def isvisible() -> bool: ...
449
450 # Note: signatures 1 and 2 overlap unsafely when no arguments are provided
451 @overload
452 def pen() -> _PenState: ...  # type: ignore
453 @overload
454 def pen(
455     pen: _PenState | None = ...,
456     *,
457     shown: bool = ...,
458     pendown: bool = ...,
459     pencolor: _Color = ...,
460     fillcolor: _Color = ...,
461     pensize: int = ...,
462     speed: int = ...,
463     resizemode: str = ...,
464     stretchfactor: tuple[float, float] = ...,
465     outline: int = ...,
466     tilt: float = ...,
467 ) -> None: ...
468
469 width = pensize
470 up = penup
471 pu = penup
472 pd = pendown
473 down = pendown
474 st = showturtle
475 ht = hideturtle
476
477 # Functions copied from RawTurtle:
478
479 def setundobuffer(size: int | None) -> None: ...
480 def undobufferentries() -> int: ...
481 @overload
482 def shape(name: None = ...) -> str: ...
483 @overload
484 def shape(name: str) -> None: ...
485
486 # Unsafely overlaps when no arguments are provided
487 @overload
488 def shapesize() -> tuple[float, float, float]: ...  # type: ignore
489 @overload
490 def shapesize(stretch_wid: float | None = ..., stretch_len: float | None = ..., outline: float | None = ...) -> None: ...
491 @overload
492 def shearfactor(shear: None = ...) -> float: ...
493 @overload
494 def shearfactor(shear: float) -> None: ...
495
496 # Unsafely overlaps when no arguments are provided
497 @overload
498 def shapetransform() -> tuple[float, float, float, float]: ...  # type: ignore
499 @overload
500 def shapetransform(
501     t11: float | None = ..., t12: float | None = ..., t21: float | None = ..., t22: float | None = ...
502 ) -> None: ...
503 def get_shapepoly() -> _PolygonCoords | None: ...
504 def settiltangle(angle: float) -> None: ...
505 @overload
506 def tiltangle(angle: None = ...) -> float: ...
507 @overload
508 def tiltangle(angle: float) -> None: ...
509 def tilt(angle: float) -> None: ...
510
511 # Can return either 'int' or Tuple[int, ...] based on if the stamp is
512 # a compound stamp or not. So, as per the "no Union return" policy,
513 # we return Any.
514 def stamp() -> Any: ...
515 def clearstamp(stampid: int | Tuple[int, ...]) -> None: ...
516 def clearstamps(n: int | None = ...) -> None: ...
517 def filling() -> bool: ...
518 def begin_fill() -> None: ...
519 def end_fill() -> None: ...
520 def dot(size: int | None = ..., *color: _Color) -> None: ...
521 def write(arg: object, move: bool = ..., align: str = ..., font: tuple[str, int, str] = ...) -> None: ...
522 def begin_poly() -> None: ...
523 def end_poly() -> None: ...
524 def get_poly() -> _PolygonCoords | None: ...
525 def getscreen() -> TurtleScreen: ...
526 def getturtle() -> Turtle: ...
527
528 getpen = getturtle
529
530 def onrelease(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ...
531 def ondrag(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ...
532 def undo() -> None: ...
533
534 turtlesize = shapesize
535
536 # Functions copied from RawTurtle with a few tweaks:
537
538 def clone() -> Turtle: ...
539
540 # Extra functions present only in the global scope:
541
542 done = mainloop