Skip to content

Commit 25300fa

Browse files
committed
Use python 3.9isms in code, examples and docs
1 parent 775a50a commit 25300fa

File tree

7 files changed

+22
-35
lines changed

7 files changed

+22
-35
lines changed

docs/reST/ref/sprite.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ Sprites are not thread safe. So lock them yourself if using threads.
291291
.. method:: draw
292292

293293
| :sl:`blit the Sprite images`
294-
| :sg:`draw(Surface) -> List[Rect]`
294+
| :sg:`draw(Surface) -> list[Rect]`
295295
296296
Draws the contained Sprites to the Surface argument. This uses the
297297
``Sprite.image`` attribute for the source surface, and ``Sprite.rect``

examples/stars.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
"""
1212

1313
import random
14-
from typing import List
1514

1615
import pygame
1716

1817

1918
class Particle:
2019
def __init__(
2120
self,
22-
pos: List[int],
21+
pos: list[int],
2322
vel: pygame.Vector2,
2423
):
2524
"""
@@ -55,7 +54,7 @@ def update(self):
5554
self.pos += self.vel
5655

5756

58-
def create_particle(particle_list: List[Particle], pos: pygame.Vector2):
57+
def create_particle(particle_list: list[Particle], pos: pygame.Vector2):
5958
"""
6059
Creates a new particle
6160
Parameters:
@@ -71,7 +70,7 @@ def create_particle(particle_list: List[Particle], pos: pygame.Vector2):
7170
)
7271

7372

74-
def update_particles(particle_list: List[Particle], screen_rect: pygame.Rect):
73+
def update_particles(particle_list: list[Particle], screen_rect: pygame.Rect):
7574
"""
7675
Updates the particles
7776
Parameters:
@@ -87,7 +86,7 @@ def update_particles(particle_list: List[Particle], screen_rect: pygame.Rect):
8786
particle.update()
8887

8988

90-
def draw_particles(particle_list: List[Particle], display: pygame.Surface):
89+
def draw_particles(particle_list: list[Particle], display: pygame.Surface):
9190
"""
9291
Draws the particles
9392
Parameters:

examples/textinput.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
Shows how to use the TEXTEDITING and TEXTINPUT events.
77
"""
88

9-
from typing import Tuple, List
109
import sys
1110
import os
1211

@@ -39,8 +38,8 @@ class TextInput:
3938
def __init__(
4039
self,
4140
prompt: str,
42-
pos: Tuple[int, int],
43-
screen_dimensions: Tuple[int, int],
41+
pos: tuple[int, int],
42+
screen_dimensions: tuple[int, int],
4443
print_event: bool,
4544
text_color="white",
4645
fps: int = 50,
@@ -77,7 +76,7 @@ def __init__(
7776

7877
print("Using font: " + self.font.name)
7978

80-
def update(self, events: List[pygame.Event]) -> None:
79+
def update(self, events: list[pygame.Event]) -> None:
8180
"""
8281
Updates the text input widget
8382
"""

src_c/cython/pygame/_sdl2/audio.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_audio_device_names(iscapture = False):
5151
If True return devices available for capture.
5252
5353
:return: list of devicenames.
54-
:rtype: List[string]
54+
:rtype: list[string]
5555
"""
5656

5757
cdef int count = SDL_GetNumAudioDevices(iscapture)

src_c/doc/sprite_doc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define DOC_SPRITE_GROUP_REMOVE "remove(*sprites) -> None\nremove Sprites from the Group"
1616
#define DOC_SPRITE_GROUP_HAS "has(*sprites) -> bool\ntest if a Group contains Sprites"
1717
#define DOC_SPRITE_GROUP_UPDATE "update(*args, **kwargs) -> None\ncall the update method on contained Sprites"
18-
#define DOC_SPRITE_GROUP_DRAW "draw(Surface) -> List[Rect]\nblit the Sprite images"
18+
#define DOC_SPRITE_GROUP_DRAW "draw(Surface) -> list[Rect]\nblit the Sprite images"
1919
#define DOC_SPRITE_GROUP_CLEAR "clear(Surface_dest, background) -> None\ndraw a background over the Sprites"
2020
#define DOC_SPRITE_GROUP_EMPTY "empty() -> None\nremove all Sprites"
2121
#define DOC_SPRITE_RENDERUPDATES "RenderUpdates(*sprites) -> RenderUpdates\nGroup sub-class that tracks dirty updates."

src_py/_debug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import sys
55
import traceback
66
import importlib
7-
from typing import Tuple, Optional, Callable
7+
from typing import Optional, Callable
88
from os import environ
99

1010
from pygame.version import ver
1111
from pygame.system import get_cpu_instruction_sets
1212

13-
ImportResult = Tuple[str, bool, Optional[Callable]]
13+
ImportResult = tuple[str, bool, Optional[Callable]]
1414

1515

1616
def str_from_tuple(version_tuple):

src_py/pkgdata.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,16 @@ def getResource(identifier, pkgname=__name__):
2222
import os
2323

2424
try:
25-
if sys.version_info[:2] > (3, 8):
26-
from importlib.resources import files
27-
28-
def resource_exists(_package_or_requirement, _resource_name):
29-
_package_or_requirement = _package_or_requirement.split(".")[0]
30-
return files(_package_or_requirement).joinpath(_resource_name).is_file()
31-
32-
def resource_stream(_package_or_requirement, _resource_name):
33-
_package_or_requirement = _package_or_requirement.split(".")[0]
34-
ref = files(_package_or_requirement).joinpath(_resource_name)
35-
return ref.open('rb')
36-
else:
37-
from importlib import resources
38-
39-
def resource_exists(_package_or_requirement, _resource_name):
40-
_package_or_requirement = _package_or_requirement.split(".")[0]
41-
return resources.is_resource(_package_or_requirement, _resource_name) # pylint: disable=deprecated-method
42-
43-
def resource_stream(_package_or_requirement, _resource_name):
44-
_package_or_requirement = _package_or_requirement.split(".")[0]
45-
return resources.open_binary(_package_or_requirement, _resource_name) # pylint: disable=deprecated-method
25+
from importlib.resources import files
26+
27+
def resource_exists(_package_or_requirement, _resource_name):
28+
_package_or_requirement = _package_or_requirement.split(".")[0]
29+
return files(_package_or_requirement).joinpath(_resource_name).is_file()
30+
31+
def resource_stream(_package_or_requirement, _resource_name):
32+
_package_or_requirement = _package_or_requirement.split(".")[0]
33+
ref = files(_package_or_requirement).joinpath(_resource_name)
34+
return ref.open("rb")
4635

4736
except ImportError:
4837

0 commit comments

Comments
 (0)