Skip to content

Commit

Permalink
Use python 3.9isms in code, examples and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Nov 17, 2024
1 parent df5367c commit cf3eff0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/reST/ref/sprite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Sprites are not thread safe. So lock them yourself if using threads.
.. method:: draw

| :sl:`blit the Sprite images`
| :sg:`draw(Surface) -> List[Rect]`
| :sg:`draw(Surface) -> list[Rect]`
Draws the contained Sprites to the Surface argument. This uses the
``Sprite.image`` attribute for the source surface, and ``Sprite.rect``
Expand Down
9 changes: 4 additions & 5 deletions examples/stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
"""

import random
from typing import List

import pygame


class Particle:
def __init__(
self,
pos: List[int],
pos: list[int],
vel: pygame.Vector2,
):
"""
Expand Down Expand Up @@ -55,7 +54,7 @@ def update(self):
self.pos += self.vel


def create_particle(particle_list: List[Particle], pos: pygame.Vector2):
def create_particle(particle_list: list[Particle], pos: pygame.Vector2):
"""
Creates a new particle
Parameters:
Expand All @@ -71,7 +70,7 @@ def create_particle(particle_list: List[Particle], pos: pygame.Vector2):
)


def update_particles(particle_list: List[Particle], screen_rect: pygame.Rect):
def update_particles(particle_list: list[Particle], screen_rect: pygame.Rect):
"""
Updates the particles
Parameters:
Expand All @@ -87,7 +86,7 @@ def update_particles(particle_list: List[Particle], screen_rect: pygame.Rect):
particle.update()


def draw_particles(particle_list: List[Particle], display: pygame.Surface):
def draw_particles(particle_list: list[Particle], display: pygame.Surface):
"""
Draws the particles
Parameters:
Expand Down
7 changes: 3 additions & 4 deletions examples/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Shows how to use the TEXTEDITING and TEXTINPUT events.
"""

from typing import Tuple, List
import sys
import os

Expand Down Expand Up @@ -39,8 +38,8 @@ class TextInput:
def __init__(
self,
prompt: str,
pos: Tuple[int, int],
screen_dimensions: Tuple[int, int],
pos: tuple[int, int],
screen_dimensions: tuple[int, int],
print_event: bool,
text_color="white",
fps: int = 50,
Expand Down Expand Up @@ -77,7 +76,7 @@ def __init__(

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

def update(self, events: List[pygame.Event]) -> None:
def update(self, events: list[pygame.Event]) -> None:
"""
Updates the text input widget
"""
Expand Down
2 changes: 1 addition & 1 deletion src_c/cython/pygame/_sdl2/audio.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_audio_device_names(iscapture = False):
If True return devices available for capture.
:return: list of devicenames.
:rtype: List[string]
:rtype: list[string]
"""

cdef int count = SDL_GetNumAudioDevices(iscapture)
Expand Down
2 changes: 1 addition & 1 deletion src_c/doc/sprite_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define DOC_SPRITE_GROUP_REMOVE "remove(*sprites) -> None\nremove Sprites from the Group"
#define DOC_SPRITE_GROUP_HAS "has(*sprites) -> bool\ntest if a Group contains Sprites"
#define DOC_SPRITE_GROUP_UPDATE "update(*args, **kwargs) -> None\ncall the update method on contained Sprites"
#define DOC_SPRITE_GROUP_DRAW "draw(Surface) -> List[Rect]\nblit the Sprite images"
#define DOC_SPRITE_GROUP_DRAW "draw(Surface) -> list[Rect]\nblit the Sprite images"
#define DOC_SPRITE_GROUP_CLEAR "clear(Surface_dest, background) -> None\ndraw a background over the Sprites"
#define DOC_SPRITE_GROUP_EMPTY "empty() -> None\nremove all Sprites"
#define DOC_SPRITE_RENDERUPDATES "RenderUpdates(*sprites) -> RenderUpdates\nGroup sub-class that tracks dirty updates."
Expand Down
5 changes: 3 additions & 2 deletions src_py/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import sys
import traceback
import importlib
from typing import Tuple, Optional, Callable
from collections.abc import Callable
from typing import Optional
from os import environ

from pygame.version import ver
from pygame.system import get_cpu_instruction_sets

ImportResult = Tuple[str, bool, Optional[Callable]]
ImportResult = tuple[str, bool, Optional[Callable]]


def str_from_tuple(version_tuple):
Expand Down
31 changes: 10 additions & 21 deletions src_py/pkgdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,16 @@ def getResource(identifier, pkgname=__name__):
import os

try:
if sys.version_info[:2] > (3, 8):
from importlib.resources import files

def resource_exists(_package_or_requirement, _resource_name):
_package_or_requirement = _package_or_requirement.split(".")[0]
return files(_package_or_requirement).joinpath(_resource_name).is_file()

def resource_stream(_package_or_requirement, _resource_name):
_package_or_requirement = _package_or_requirement.split(".")[0]
ref = files(_package_or_requirement).joinpath(_resource_name)
return ref.open('rb')
else:
from importlib import resources

def resource_exists(_package_or_requirement, _resource_name):
_package_or_requirement = _package_or_requirement.split(".")[0]
return resources.is_resource(_package_or_requirement, _resource_name) # pylint: disable=deprecated-method

def resource_stream(_package_or_requirement, _resource_name):
_package_or_requirement = _package_or_requirement.split(".")[0]
return resources.open_binary(_package_or_requirement, _resource_name) # pylint: disable=deprecated-method
from importlib.resources import files

def resource_exists(_package_or_requirement, _resource_name):
_package_or_requirement = _package_or_requirement.split(".")[0]
return files(_package_or_requirement).joinpath(_resource_name).is_file()

def resource_stream(_package_or_requirement, _resource_name):
_package_or_requirement = _package_or_requirement.split(".")[0]
ref = files(_package_or_requirement).joinpath(_resource_name)
return ref.open("rb")

except ImportError:

Expand Down

0 comments on commit cf3eff0

Please sign in to comment.