Skip to content

Commit

Permalink
Merge pull request pygame-community#3147 from zoldalma999/misc-fixes
Browse files Browse the repository at this point in the history
Fix stubcheck error on windows, mark typealiases as such in typing
  • Loading branch information
ankith26 authored Oct 6, 2024
2 parents 1a57252 + 022f3b3 commit 16a8fd0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
1 change: 0 additions & 1 deletion buildconfig/stubs/pygame/geometry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ from typing import (

from pygame import Rect, FRect
from pygame.typing import Point, RectLike, SequenceLike
from .rect import Rect, FRect
from .math import Vector2

_CanBeCircle = Union[Circle, Tuple[Point, float], SequenceLike[float]]
Expand Down
16 changes: 8 additions & 8 deletions buildconfig/stubs/pygame/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ __all__ = [

import sys
from abc import abstractmethod
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, TypeAlias

if sys.version_info >= (3, 9):
from os import PathLike as _PathProtocol
Expand All @@ -27,9 +27,9 @@ else:


# For functions that take a file name
_PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
_PathLike: TypeAlias = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
# Most pygame functions that take a file argument should be able to handle a FileLike type
FileLike = Union[_PathLike, IO[bytes], IO[str]]
FileLike: TypeAlias = Union[_PathLike, IO[bytes], IO[str]]

_T_co = TypeVar("_T_co", covariant=True)

Expand All @@ -49,11 +49,11 @@ class SequenceLike(Protocol[_T_co]):

# Pygame handles float without errors in most cases where a point is expected,
# usually rounding to int. Also, 'Union[int, float] == float'
Point = SequenceLike[float]
Point: TypeAlias = SequenceLike[float]
# This is used where ints are strictly required
IntPoint = SequenceLike[int]
IntPoint: TypeAlias = SequenceLike[int]

ColorLike = Union[int, str, SequenceLike[int]]
ColorLike: TypeAlias = Union[int, str, SequenceLike[int]]


class _HasRectAttribute(Protocol):
Expand All @@ -63,8 +63,8 @@ class _HasRectAttribute(Protocol):
def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ...


RectLike = Union[SequenceLike[float], SequenceLike[Point], _HasRectAttribute]
RectLike: TypeAlias = Union[SequenceLike[float], SequenceLike[Point], _HasRectAttribute]


# cleanup namespace
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol, TypeAlias
3 changes: 2 additions & 1 deletion src_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@
except (FileNotFoundError, ValueError):
pass

d = "" # define variable here so that we can consistently delete it
for d in dll_parents:
# adding to PATH is the legacy way, os.add_dll_directory is the new
# and recommended method. For extra safety we do both
os.environ["PATH"] = os.environ["PATH"] + ";" + d
os.add_dll_directory(d)

# cleanup namespace
del pygame_dir, dll_parents
del pygame_dir, dll_parents, d

# when running under X11, always set the SDL window WM_CLASS to make the
# window managers correctly match the pygame window.
Expand Down
16 changes: 8 additions & 8 deletions src_py/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import sys
from abc import abstractmethod
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, TypeAlias

if sys.version_info >= (3, 9):
from os import PathLike as _PathProtocol
Expand All @@ -27,9 +27,9 @@ def __fspath__(self) -> _AnyStr_co: ...


# For functions that take a file name
_PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
_PathLike: TypeAlias = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
# Most pygame functions that take a file argument should be able to handle a FileLike type
FileLike = Union[_PathLike, IO[bytes], IO[str]]
FileLike: TypeAlias = Union[_PathLike, IO[bytes], IO[str]]

_T_co = TypeVar("_T_co", covariant=True)

Expand All @@ -49,11 +49,11 @@ def __len__(self) -> int: ...

# Pygame handles float without errors in most cases where a point is expected,
# usually rounding to int. Also, 'Union[int, float] == float'
Point = SequenceLike[float]
Point: TypeAlias = SequenceLike[float]
# This is used where ints are strictly required
IntPoint = SequenceLike[int]
IntPoint: TypeAlias = SequenceLike[int]

ColorLike = Union[int, str, SequenceLike[int]]
ColorLike: TypeAlias = Union[int, str, SequenceLike[int]]


class _HasRectAttribute(Protocol):
Expand All @@ -63,8 +63,8 @@ class _HasRectAttribute(Protocol):
def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ...


RectLike = Union[SequenceLike[float], SequenceLike[Point], _HasRectAttribute]
RectLike: TypeAlias = Union[SequenceLike[float], SequenceLike[Point], _HasRectAttribute]


# cleanup namespace
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol, TypeAlias

0 comments on commit 16a8fd0

Please sign in to comment.