Skip to content

Commit ef7fa50

Browse files
authored
Mypy/fix pep 484 (#1399)
* fix mypy issues for PEP 484 and more * make SpriteList generic
1 parent 9017ae1 commit ef7fa50

34 files changed

Lines changed: 168 additions & 163 deletions

arcade/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
# Error out if we import Arcade with an incompatible version of Python.
99
import sys
1010
import os
11+
from typing import Optional
1112

1213
from pathlib import Path
1314

1415
if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 7):
1516
sys.exit("The Arcade Library requires Python 3.7 or higher.")
1617

1718

18-
def configure_logging(level: int = None):
19+
def configure_logging(level: Optional[int] = None):
1920
"""Set up basic logging.
2021
:param int level: The log level. Defaults to DEBUG.
2122
"""
@@ -340,7 +341,6 @@ def configure_logging(level: int = None):
340341
Text,
341342
)
342343

343-
344344
__all__ = ['AStarBarrierList',
345345
'AnimatedTimeBasedSprite',
346346
'AnimatedWalkingSprite',

arcade/application.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def close(self):
277277
def set_fullscreen(self,
278278
fullscreen: bool = True,
279279
screen: Optional['Window'] = None,
280-
mode: ScreenMode = None,
280+
mode: Optional[ScreenMode] = None,
281281
width: Optional[float] = None,
282282
height: Optional[float] = None):
283283
"""
@@ -902,7 +902,7 @@ class View:
902902
"""
903903

904904
def __init__(self,
905-
window: Window = None):
905+
window: Optional[Window] = None):
906906

907907
self.window = arcade.get_window() if window is None else window
908908
self.key: Optional[int] = None
@@ -934,7 +934,7 @@ def clear(
934934
self,
935935
color: Optional[Color] = None,
936936
normalized: bool = False,
937-
viewport: Tuple[int, int, int, int] = None,
937+
viewport: Optional[Tuple[int, int, int, int]] = None,
938938
):
939939
"""Clears the View's Window with the configured background color
940940
set through :py:attr:`arcade.Window.background_color`.

arcade/background/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Tuple
1+
from typing import Optional, Tuple
22

33
from PIL import Image
44

@@ -42,16 +42,16 @@ def texture_from_file(
4242
def background_from_file(
4343
tex_src: str,
4444
pos: Tuple[float, float] = (0.0, 0.0),
45-
size: Tuple[int, int] = None,
45+
size: Optional[Tuple[int, int]] = None,
4646
offset: Tuple[float, float] = (0.0, 0.0),
4747
scale: float = 1.0,
4848
angle: float = 0.0,
4949
*,
5050
filters=(gl.NEAREST, gl.NEAREST),
51-
color: Tuple[int, int, int] = None,
52-
color_norm: Tuple[float, float, float] = None,
53-
shader: gl.Program = None,
54-
geometry: gl.Geometry = None
51+
color: Optional[Tuple[int, int, int]] = None,
52+
color_norm: Optional[Tuple[float, float, float]] = None,
53+
shader: Optional[gl.Program] = None,
54+
geometry: Optional[gl.Geometry] = None
5555
) -> Background:
5656

5757
texture = BackgroundTexture.from_file(tex_src, offset, scale, angle, filters)

arcade/background/background.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Union, Tuple
1+
from typing import Optional, Union, Tuple
22

33
from arcade.window_commands import get_window
44
import arcade.gl as gl
@@ -24,8 +24,8 @@ def __init__(
2424
pos: Tuple[float, float],
2525
size: Tuple[int, int],
2626
color: Union[Tuple[float, float, float], Tuple[int, int, int]],
27-
shader: gl.Program = None,
28-
geometry: gl.Geometry = None,
27+
shader: Optional[gl.Program] = None,
28+
geometry: Optional[gl.Geometry] = None,
2929
):
3030

3131
if shader is None:
@@ -81,16 +81,16 @@ def __init__(
8181
def from_file(
8282
tex_src: str,
8383
pos: Tuple[float, float] = (0.0, 0.0),
84-
size: Tuple[int, int] = None,
84+
size: Optional[Tuple[int, int]] = None,
8585
offset: Tuple[float, float] = (0.0, 0.0),
8686
scale: float = 1.0,
8787
angle: float = 0.0,
8888
*,
8989
filters=(gl.NEAREST, gl.NEAREST),
90-
color: Tuple[int, int, int] = None,
91-
color_norm: Tuple[float, float, float] = None,
92-
shader: gl.Program = None,
93-
geometry: gl.Geometry = None
90+
color: Optional[Tuple[int, int, int]] = None,
91+
color_norm: Optional[Tuple[float, float, float]] = None,
92+
shader: Optional[gl.Program] = None,
93+
geometry: Optional[gl.Geometry] = None
9494
):
9595
"""
9696
This will generate a Background from an input image source. The generated texture is not stored in the

arcade/background/background_texture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Tuple
1+
from typing import Optional, List, Tuple
22

33
from PIL import Image
44

@@ -123,8 +123,8 @@ def use(self, unit: int = 0) -> None:
123123
def render_target(
124124
self,
125125
context: ArcadeContext,
126-
color_attachments: List[gl.Texture] = None,
127-
depth_attachment: gl.Texture = None,
126+
color_attachments: Optional[List[gl.Texture]] = None,
127+
depth_attachment: Optional[gl.Texture] = None,
128128
) -> gl.Framebuffer:
129129
if color_attachments is None:
130130
color_attachments = []

arcade/background/groups.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Union, List, Tuple
1+
from typing import Optional, Union, List, Tuple
22

33
import arcade.gl as gl
44
from arcade.background import Background
@@ -11,7 +11,7 @@ class BackgroundGroup:
1111
The offset of the BackgroundGroup is the same as each background.
1212
"""
1313

14-
def __init__(self, backgrounds: List[Background] = None):
14+
def __init__(self, backgrounds: Optional[List[Background]] = None):
1515
self._backgrounds: List[Background] = [] if backgrounds is None else backgrounds
1616

1717
self._pos = (0.0, 0.0)
@@ -63,16 +63,16 @@ def add_from_file(
6363
self,
6464
tex_src: str,
6565
pos: Tuple[float, float] = (0.0, 0.0),
66-
size: Tuple[int, int] = None,
66+
size: Optional[Tuple[int, int]] = None,
6767
offset: Tuple[float, float] = (0.0, 0.0),
6868
scale: float = 1.0,
6969
angle: float = 0.0,
7070
*,
7171
filters=(gl.NEAREST, gl.NEAREST),
72-
color: Tuple[int, int, int] = None,
73-
color_norm: Tuple[float, float, float] = None,
74-
shader: gl.Program = None,
75-
geometry: gl.Geometry = None
72+
color: Optional[Tuple[int, int, int]] = None,
73+
color_norm: Optional[Tuple[float, float, float]] = None,
74+
shader: Optional[gl.Program] = None,
75+
geometry: Optional[gl.Geometry] = None
7676
):
7777
background = Background.from_file(
7878
tex_src,
@@ -100,7 +100,7 @@ class ParallaxGroup:
100100
"""
101101

102102
def __init__(
103-
self, backgrounds: List[Background] = None, depths: List[float] = None
103+
self, backgrounds: Optional[List[Background]] = None, depths: Optional[List[float]] = None
104104
):
105105
self._backgrounds: List[Background] = [] if backgrounds is None else backgrounds
106106
self._depths: List[float] = [] if depths is None else depths
@@ -168,17 +168,17 @@ def add_from_file(
168168
self,
169169
tex_src: str,
170170
pos: Tuple[float, float] = (0.0, 0.0),
171-
size: Tuple[int, int] = None,
171+
size: Optional[Tuple[int, int]] = None,
172172
depth: float = 1,
173173
offset: Tuple[float, float] = (0.0, 0.0),
174174
scale: float = 1.0,
175175
angle: float = 0.0,
176176
*,
177177
filters=(gl.NEAREST, gl.NEAREST),
178-
color: Tuple[int, int, int] = None,
179-
color_norm: Tuple[float, float, float] = None,
180-
shader: gl.Program = None,
181-
geometry: gl.Geometry = None
178+
color: Optional[Tuple[int, int, int]] = None,
179+
color_norm: Optional[Tuple[float, float, float]] = None,
180+
shader: Optional[gl.Program] = None,
181+
geometry: Optional[gl.Geometry] = None
182182
):
183183
background = Background.from_file(
184184
tex_src,

arcade/camera.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class SimpleCamera:
2727
"""
2828

2929
def __init__(self, *,
30-
viewport: FourIntTuple = None,
31-
projection: FourFloatTuple = None,
30+
viewport: Optional[FourIntTuple] = None,
31+
projection: Optional[FourFloatTuple] = None,
3232
window: Optional["arcade.Window"] = None) -> None:
3333

3434
# Reference to Context, used to update projection matrix

arcade/draw_commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import pyglet.gl as gl
1919

20-
from typing import Tuple
20+
from typing import Optional, Tuple
2121

2222
from arcade import Color
2323
from arcade import PointList
@@ -877,7 +877,7 @@ def get_pixel(x: int, y: int, components: int = 3) -> Tuple[int, ...]:
877877
return tuple(int(i) for i in a[:components])
878878

879879

880-
def get_image(x: int = 0, y: int = 0, width: int = None, height: int = None) -> PIL.Image.Image:
880+
def get_image(x: int = 0, y: int = 0, width: Optional[int] = None, height: Optional[int] = None) -> PIL.Image.Image:
881881
"""
882882
Get an image from the screen.
883883

arcade/emitter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import arcade
77
from arcade.particle import Particle
8-
from typing import Callable, cast
8+
from typing import Optional, Callable, cast
99
from arcade.utils import _Vec2
1010
from arcade.arcade_types import Point, Vector
1111

@@ -109,8 +109,8 @@ def __init__(
109109
emit_controller: EmitController,
110110
particle_factory: Callable[["Emitter"], Particle],
111111
change_xy: Vector = (0.0, 0.0),
112-
emit_done_cb: Callable[["Emitter"], None] = None,
113-
reap_cb: Callable[[], None] = None
112+
emit_done_cb: Optional[Callable[["Emitter"], None]] = None,
113+
reap_cb: Optional[Callable[[], None]] = None
114114
):
115115
# Note Self-reference with type annotations:
116116
# https://www.python.org/dev/peps/pep-0484/#the-problem-of-forward-declarations

arcade/examples/performance_statistics.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
python -m arcade.examples.performance_statistics
2121
"""
2222
import random
23+
from typing import Optional
24+
2325
import arcade
2426

2527
# --- Constants ---
@@ -74,9 +76,9 @@ def __init__(self):
7476
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
7577

7678
# Variables to hold game objects and performance info
77-
self.coin_list: arcade.SpriteList = None
78-
self.perf_graph_list: arcade.SpriteList = None
79-
self.fps_text: arcade.Text = None
79+
self.coin_list: Optional[arcade.SpriteList] = None
80+
self.perf_graph_list: Optional[arcade.SpriteList] = None
81+
self.fps_text: Optional[arcade.Text] = None
8082
self.frame_count: int = 0 # for tracking the reset interval
8183

8284
arcade.set_background_color(arcade.color.AMAZON)

0 commit comments

Comments
 (0)