Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing type hints #1720

Draft
wants to merge 70 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
f9de04d
1st version
Apr 23, 2023
4cc412c
Add more Type Hints
Apr 24, 2023
2c4ecc8
Fix cspotcode's review
Apr 24, 2023
0d166e4
Add types to sprite.py
Apr 24, 2023
3076ed4
Try to fix some issues
Apr 24, 2023
97cb872
Fixed more github stuff
Apr 24, 2023
c3c590f
Fix easing.py somewhat
Apr 24, 2023
ffedb28
Mics changes bc tests are breaking
Apr 24, 2023
be086d0
.
Apr 24, 2023
06b6ddd
Changes bc git complained
Apr 25, 2023
171af9b
Fixes problems in 4 files
Apr 25, 2023
9623b62
Attempt to fix git again
Apr 26, 2023
a432ca6
type hint problems in property.py
Apr 27, 2023
5294ea1
attempts to fix property.py
Apr 28, 2023
5b0d1f0
I was misunderstanding the test error messages
Apr 28, 2023
211f6a2
.
Apr 28, 2023
3698b0f
Attempt to fix property
Apr 28, 2023
51a15eb
.
Apr 28, 2023
71ef4b2
.
Apr 28, 2023
7de2f68
Check changes in mixins.py
Apr 29, 2023
7873b18
Address no slots in View
May 3, 2023
f50d5e7
Partially added __slots__
May 3, 2023
4b3789d
Role back __slots__
May 3, 2023
8563913
.
May 6, 2023
18c7c2c
.
May 6, 2023
857ec84
Merge branch 'pythonarcade:development' into AddMissingTypeHints
gran4 May 6, 2023
8d4fdd0
(View)
May 6, 2023
98fe26e
Merge branch 'AddMissingTypeHints' of https://github.com/gran4/arcade…
May 6, 2023
545fde1
.
May 6, 2023
bfc4bc8
.
May 6, 2023
cb74764
.
May 6, 2023
3d52f73
.
May 6, 2023
5c6e5d6
.
May 6, 2023
f581cbf
.
May 6, 2023
2d44801
.
May 6, 2023
a2097f1
.
May 6, 2023
30b5b26
Add imports to mixins
May 6, 2023
9ee32fb
Change import in mixins
May 6, 2023
b8ab035
Fix shape_list.py
May 6, 2023
b17ffb5
Changed pyproject.toml as @pushfoo sugested
May 7, 2023
a2c6f5c
Revert pyproject change
May 7, 2023
f2ffcab
Add # type: ignore
May 10, 2023
b386371
Small errors fixed
May 12, 2023
9ba0c55
.
May 18, 2023
1ce4b19
Merge branch 'development' into AddMissingTypeHints
gran4 May 23, 2023
16cccf6
Update arcade/application.py
gran4 May 26, 2023
5a8e8fb
Update arcade/gui/property.py
gran4 May 26, 2023
60b6f3d
cspotcode's fixes
May 26, 2023
0034450
//
May 26, 2023
a81a701
Merge branch 'AddMissingTypeHints' of https://github.com/gran4/arcade…
May 26, 2023
1c0af3c
lol
May 26, 2023
93761b6
added future immport annotations
May 26, 2023
5fe6a23
Remove generics
May 27, 2023
7f6de70
Requested fixes
Jun 3, 2023
a3e51d4
correct import in application
Jun 3, 2023
a5a6fc7
Add # type: ignore to speed it up
Jun 3, 2023
58805a7
Line was too long
Jun 4, 2023
3e867fa
Fixes
Jun 13, 2023
971e8f5
Merge branch 'pythonarcade:development' into AddMissingTypeHints
gran4 Jun 17, 2023
29e8632
..
Jun 17, 2023
99595de
Merge branch 'AddMissingTypeHints' of https://github.com/gran4/arcade…
Jun 17, 2023
6a0a779
...
Jun 17, 2023
135f7ca
..
Jun 18, 2023
4b344bf
.
Jun 18, 2023
aeb3819
.
gran4 Jun 22, 2023
929d87f
.
gran4 Jun 22, 2023
eb1f7d7
.
gran4 Jun 28, 2023
53237fa
.
gran4 Jul 5, 2023
21f3a8b
.
gran4 Jul 5, 2023
bc472c2
Update draw_commands.py
gran4 Sep 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
134 changes: 67 additions & 67 deletions arcade/application.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion arcade/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ArcadeContext(Context):

atlas_size = 512, 512

def __init__(self, window: pyglet.window.Window, gc_mode: str = "context_gc", gl_api: str = "gl"):
def __init__(self, window: pyglet.window.Window, gc_mode: str = "context_gc", gl_api: str = "gl") -> None:
gran4 marked this conversation as resolved.
Show resolved Hide resolved

super().__init__(window, gc_mode=gc_mode, gl_api=gl_api)

Expand Down
67 changes: 36 additions & 31 deletions arcade/draw_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def draw_arc_filled(center_x: float, center_y: float,
color: RGBA255,
start_angle: float, end_angle: float,
tilt_angle: float = 0,
num_segments: int = 128):
num_segments: int = 128) -> None:
"""
Draw a filled in arc. Useful for drawing pie-wedges, or Pac-Man.

Expand Down Expand Up @@ -76,7 +76,7 @@ def draw_arc_outline(center_x: float, center_y: float, width: float,
height: float, color: RGBA255,
start_angle: float, end_angle: float,
border_width: float = 1, tilt_angle: float = 0,
num_segments: int = 128):
num_segments: int = 128) -> None:
"""
Draw the outside edge of an arc. Useful for drawing curved lines.

Expand Down Expand Up @@ -132,7 +132,7 @@ def draw_arc_outline(center_x: float, center_y: float, width: float,

def draw_parabola_filled(start_x: float, start_y: float, end_x: float,
height: float, color: RGBA255,
tilt_angle: float = 0):
tilt_angle: float = 0) -> None:
"""
Draws a filled in parabola.

Expand All @@ -155,7 +155,7 @@ def draw_parabola_filled(start_x: float, start_y: float, end_x: float,

def draw_parabola_outline(start_x: float, start_y: float, end_x: float,
height: float, color: RGBA255,
border_width: float = 1, tilt_angle: float = 0):
border_width: float = 1, tilt_angle: float = 0) -> None:
"""
Draws the outline of a parabola.

Expand Down Expand Up @@ -185,7 +185,7 @@ def draw_parabola_outline(start_x: float, start_y: float, end_x: float,
def draw_circle_filled(center_x: float, center_y: float, radius: float,
color: RGBA255,
tilt_angle: float = 0,
num_segments: int = -1):
num_segments: int = -1) -> None:
"""
Draw a filled-in circle.

Expand All @@ -208,7 +208,7 @@ def draw_circle_filled(center_x: float, center_y: float, radius: float,
def draw_circle_outline(center_x: float, center_y: float, radius: float,
color: RGBA255, border_width: float = 1,
tilt_angle: float = 0,
num_segments: int = -1):
num_segments: int = -1) -> None:
"""
Draw the outline of a circle.

Expand Down Expand Up @@ -239,7 +239,7 @@ def draw_circle_outline(center_x: float, center_y: float, radius: float,

def draw_ellipse_filled(center_x: float, center_y: float,
width: float, height: float, color: RGBA255,
tilt_angle: float = 0, num_segments: int = -1):
tilt_angle: float = 0, num_segments: int = -1) -> None:
"""
Draw a filled in ellipse.

Expand Down Expand Up @@ -286,7 +286,7 @@ def draw_ellipse_outline(center_x: float, center_y: float,
height: float, color: RGBA255,
border_width: float = 1,
tilt_angle: float = 0,
num_segments: int = -1):
num_segments: int = -1) -> None:
"""
Draw the outline of an ellipse.

Expand Down Expand Up @@ -335,7 +335,7 @@ def draw_ellipse_outline(center_x: float, center_y: float,

def _generic_draw_line_strip(point_list: PointList,
color: RGBA255,
mode: int = gl.GL_LINE_STRIP):
mode: int = gl.GL_LINE_STRIP) -> None:
"""
Draw a line strip. A line strip is a set of continuously connected
line segments.
Expand Down Expand Up @@ -372,7 +372,8 @@ def _generic_draw_line_strip(point_list: PointList,


def draw_line_strip(point_list: PointList,
color: RGBA255, line_width: float = 1):
color: RGBA255,
line_width: float = 1) -> None:
"""
Draw a multi-point line.

Expand All @@ -397,7 +398,7 @@ def draw_line_strip(point_list: PointList,


def draw_line(start_x: float, start_y: float, end_x: float, end_y: float,
color: RGBA255, line_width: float = 1):
color: RGBA255, line_width: float = 1) -> None:
"""
Draw a line.

Expand Down Expand Up @@ -432,7 +433,7 @@ def draw_line(start_x: float, start_y: float, end_x: float, end_y: float,

def draw_lines(point_list: PointList,
color: RGBA255,
line_width: float = 1):
line_width: float = 1) -> None:
"""
Draw a set of lines.

Expand Down Expand Up @@ -472,7 +473,7 @@ def draw_lines(point_list: PointList,
# --- BEGIN POINT FUNCTIONS # # #


def draw_point(x: float, y: float, color: RGBA255, size: float):
def draw_point(x: float, y: float, color: RGBA255, size: float) -> None:
"""
Draw a point.

Expand All @@ -485,7 +486,7 @@ def draw_point(x: float, y: float, color: RGBA255, size: float):
draw_rectangle_filled(x, y, size, size, color)


def draw_points(point_list: PointList, color: RGBA255, size: float = 1):
def draw_points(point_list: PointList, color: RGBA255, size: float = 1) -> None:
"""
Draw a set of points.

Expand Down Expand Up @@ -526,7 +527,7 @@ def draw_points(point_list: PointList, color: RGBA255, size: float = 1):


def draw_polygon_filled(point_list: PointList,
color: RGBA255):
color: RGBA255) -> None:
"""
Draw a polygon that is filled in.

Expand All @@ -540,7 +541,8 @@ def draw_polygon_filled(point_list: PointList,


def draw_polygon_outline(point_list: PointList,
color: RGBA255, line_width: float = 1):
color: RGBA255,
line_width: float = 1) -> None:
"""
Draw a polygon outline. Also known as a "line loop."

Expand Down Expand Up @@ -571,7 +573,8 @@ def draw_polygon_outline(point_list: PointList,

def draw_triangle_filled(x1: float, y1: float,
x2: float, y2: float,
x3: float, y3: float, color: RGBA255):
x3: float, y3: float,
color: RGBA255) -> None:
"""
Draw a filled in triangle.

Expand All @@ -596,7 +599,7 @@ def draw_triangle_outline(x1: float, y1: float,
x2: float, y2: float,
x3: float, y3: float,
color: RGBA255,
border_width: float = 1):
border_width: float = 1) -> None:
"""
Draw a the outline of a triangle.

Expand Down Expand Up @@ -630,7 +633,7 @@ def draw_triangle_outline(x1: float, y1: float,
)
def draw_lrtb_rectangle_outline(left: float, right: float, top: float,
bottom: float, color: RGBA255,
border_width: float = 1):
border_width: float = 1) -> None:
"""
Draw a rectangle by specifying left, right, top and bottom edges.

Expand Down Expand Up @@ -664,7 +667,7 @@ def draw_lrtb_rectangle_outline(left: float, right: float, top: float,


def draw_lrbt_rectangle_outline(left: float, right: float, bottom: float, top: float, color: RGBA255,
border_width: float = 1):
border_width: float = 1) -> None:
"""
Draw a rectangle by specifying left, right, bottom and top edges.

Expand Down Expand Up @@ -696,7 +699,7 @@ def draw_lrbt_rectangle_outline(left: float, right: float, bottom: float, top: f
def draw_xywh_rectangle_outline(bottom_left_x: float, bottom_left_y: float,
width: float, height: float,
color: RGBA255,
border_width: float = 1):
border_width: float = 1) -> None:
"""
Draw a rectangle extending from bottom left to top right

Expand All @@ -716,7 +719,7 @@ def draw_xywh_rectangle_outline(bottom_left_x: float, bottom_left_y: float,

def draw_rectangle_outline(center_x: float, center_y: float, width: float,
height: float, color: RGBA255,
border_width: float = 1, tilt_angle: float = 0):
border_width: float = 1, tilt_angle: float = 0) -> None:
"""
Draw a rectangle outline.

Expand Down Expand Up @@ -756,7 +759,7 @@ def draw_rectangle_outline(center_x: float, center_y: float, width: float,
new_name="draw_lrbt_rectangle_filled"
)
def draw_lrtb_rectangle_filled(left: float, right: float, top: float,
bottom: float, color: RGBA255):
bottom: float, color: RGBA255) -> None:
"""
Draw a rectangle by specifying left, right, top and bottom edges.

Expand Down Expand Up @@ -784,7 +787,7 @@ def draw_lrtb_rectangle_filled(left: float, right: float, top: float,
draw_rectangle_filled(center_x, center_y, width, height, color)


def draw_lrbt_rectangle_filled(left: float, right: float, bottom: float, top: float, color: RGBA255):
def draw_lrbt_rectangle_filled(left: float, right: float, bottom: float, top: float, color: RGBA255) -> None:
"""
Draw a rectangle by specifying left, right, bottom and top edges.

Expand All @@ -810,7 +813,7 @@ def draw_lrbt_rectangle_filled(left: float, right: float, bottom: float, top: fl

def draw_xywh_rectangle_filled(bottom_left_x: float, bottom_left_y: float,
width: float, height: float,
color: RGBA255):
color: RGBA255) -> None:
"""
Draw a filled rectangle extending from bottom left to top right

Expand All @@ -828,7 +831,7 @@ def draw_xywh_rectangle_filled(bottom_left_x: float, bottom_left_y: float,

def draw_rectangle_filled(center_x: float, center_y: float, width: float,
height: float, color: RGBA255,
tilt_angle: float = 0):
tilt_angle: float = 0) -> None:
"""
Draw a filled-in rectangle.

Expand Down Expand Up @@ -865,7 +868,7 @@ def draw_scaled_texture_rectangle(center_x: float, center_y: float,
texture: Texture,
scale: float = 1.0,
angle: float = 0,
alpha: int = 255):
alpha: int = 255) -> None:
"""
Draw a textured rectangle on-screen.

Expand Down Expand Up @@ -900,7 +903,7 @@ def draw_texture_rectangle(center_x: float, center_y: float,
height: float,
texture: Texture,
angle: float = 0,
alpha: int = 255):
alpha: int = 255) -> None:
"""
Draw a textured rectangle on-screen.

Expand All @@ -915,11 +918,13 @@ def draw_texture_rectangle(center_x: float, center_y: float,
texture.draw_sized(center_x, center_y, width, height, angle, alpha)


def draw_lrwh_rectangle_textured(bottom_left_x: float, bottom_left_y: float,
def draw_lrwh_rectangle_textured(bottom_left_x: float,
bottom_left_y: float,
width: float,
height: float,
texture: Texture, angle: float = 0,
alpha: int = 255):
texture: Texture,
angle: float = 0,
alpha: int = 255) -> None:
"""
Draw a texture extending from bottom left to top right.

Expand Down
53 changes: 31 additions & 22 deletions arcade/easing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EasingData:
end_value: float
ease_function: Callable

def reset(self):
def reset(self) -> None:
self.cur_period = self.start_period


Expand Down Expand Up @@ -145,7 +145,9 @@ def easing(percent: float, easing_data: EasingData) -> float:
easing_data.ease_function(percent)


def ease_angle(start_angle: float, end_angle: float, *, time=None, rate=None, ease_function: Callable = linear):
def ease_angle(start_angle: float, end_angle: float, *,
time=None, rate=None, ease_function: Callable = linear
) -> EasingData:
"""
Set up easing for angles.
"""
Expand Down Expand Up @@ -174,16 +176,16 @@ def ease_angle(start_angle: float, end_angle: float, *, time=None, rate=None, ea
return easing_data


def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple:
def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, EasingData]:
"""
Update angle easing.
"""
done = False
done: bool = False
easing_data.cur_period += delta_time
easing_data.cur_period = min(easing_data.cur_period, easing_data.end_period)
percent = easing_data.cur_period / easing_data.end_period
percent: float = easing_data.cur_period / easing_data.end_period

angle = easing(percent, easing_data)
angle: EasingData = easing(percent, easing_data)

if percent >= 1.0:
done = True
Expand All @@ -197,17 +199,20 @@ def ease_angle_update(easing_data: EasingData, delta_time: float) -> Tuple:
return done, angle


def ease_value(start_value: float, end_value: float, *, time=None, rate=None, ease_function=linear):
def ease_value(start_value: float, end_value: float, *, time:
Optional[float]=None, rate: Optional[float]=None,
ease_function: Callable=linear) -> EasingData:
"""
Get an easing value
"""
if rate is not None:
diff = abs(start_value - end_value)
time = diff / rate

if time is None:
if not time or not rate:
eruvanos marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError("Either the 'time' or the 'rate' parameter needs to be set.")

if rate:
diff = abs(start_value - end_value)
time: float = diff / rate

easing_data = EasingData(start_value=start_value,
end_value=end_value,
start_period=0,
Expand All @@ -217,36 +222,40 @@ def ease_value(start_value: float, end_value: float, *, time=None, rate=None, ea
return easing_data


def ease_position(start_position, end_position, *, time=None, rate=None, ease_function=linear):
def ease_position(start_position: Tuple[float, float],
end_position: Tuple[float, float], *,
time: Optional[float]=None, rate:
Optional[float]=None, ease_function: Callable=linear
) -> Tuple[EasingData, EasingData]:
"""
Get an easing position
"""
distance = get_distance(start_position[0],
distance: float = get_distance(start_position[0],
start_position[1],
end_position[0],
end_position[1])

if rate is not None:
time = distance / rate

easing_data_x = ease_value(start_position[0], end_position[0], time=time, ease_function=ease_function)
easing_data_y = ease_value(start_position[1], end_position[1], time=time, ease_function=ease_function)
easing_data_x: EasingData = ease_value(start_position[0], end_position[0], time=time, ease_function=ease_function)
easing_data_y: EasingData = ease_value(start_position[1], end_position[1], time=time, ease_function=ease_function)

return easing_data_x, easing_data_y


def ease_update(easing_data: EasingData, delta_time: float) -> Tuple:
def ease_update(easing_data: EasingData, delta_time: float) -> Tuple[bool, float]:
"""
Update easing between two values/
"""
easing_data.cur_period += delta_time
easing_data.cur_period = min(easing_data.cur_period, easing_data.end_period)
easing_data.cur_period: float = min(easing_data.cur_period, easing_data.end_period)
if easing_data.end_period == 0:
percent = 1.0
value = easing_data.end_value
percent: float = 1.0
value: EasingData = easing_data.end_value
else:
percent = easing_data.cur_period / easing_data.end_period
value = easing(percent, easing_data)
percent: float = easing_data.cur_period / easing_data.end_period
value: EasingData = easing(percent, easing_data)

done = percent >= 1.0
done: bool = percent >= 1.0
return done, value