Skip to content

Commit

Permalink
Move PowerState dataclass to typing.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Sep 29, 2024
1 parent b429078 commit c8afa8d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion buildconfig/stubs/pygame/system.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional, TypedDict

from pygame._data_classes import PowerState
from pygame.typing import PowerState

class _InstructionSets(TypedDict):
ALTIVEC: bool
Expand Down
16 changes: 15 additions & 1 deletion buildconfig/stubs/pygame/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ __all__ = [

import sys
from abc import abstractmethod
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol
from dataclasses import dataclass
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, Optional


if sys.version_info >= (3, 9):
from os import PathLike as _PathProtocol
Expand Down Expand Up @@ -66,5 +68,17 @@ class _HasRectAttribute(Protocol):
RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribute]


@dataclass(frozen=True)
class PowerState:
battery_percent: Optional[int]
battery_seconds: Optional[int]
on_battery: bool
no_battery: bool
charging: bool
charged: bool
plugged_in: bool
has_battery: bool


# cleanup namespace
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol
3 changes: 1 addition & 2 deletions src_c/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ MODINIT_DEFINE(system)
return NULL;
}

PyObject *data_classes_module =
PyImport_ImportModule("pygame._data_classes");
PyObject *data_classes_module = PyImport_ImportModule("pygame.typing");
if (!data_classes_module) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def PixelArray(surface): # pylint: disable=unused-argument

try:
import pygame.system
from pygame._data_classes import PowerState as power_state
from pygame.typing import PowerState as power_state

power_state.__module__ = "pygame.system"
del power_state
Expand Down
14 changes: 0 additions & 14 deletions src_py/_data_classes.py

This file was deleted.

1 change: 0 additions & 1 deletion src_py/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
python_sources = files(
'__init__.py',
'_camera_opencv.py',
'_data_classes.py',
'_debug.py',
'_sprite.py',
'camera.py',
Expand Down
16 changes: 15 additions & 1 deletion src_py/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

import sys
from abc import abstractmethod
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol
from dataclasses import dataclass
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, Optional


if sys.version_info >= (3, 9):
from os import PathLike as _PathProtocol
Expand Down Expand Up @@ -66,5 +68,17 @@ def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ...
RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribute]


@dataclass(frozen=True)
class PowerState:
battery_percent: Optional[int]
battery_seconds: Optional[int]
on_battery: bool
no_battery: bool
charging: bool
charged: bool
plugged_in: bool
has_battery: bool


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

0 comments on commit c8afa8d

Please sign in to comment.