Skip to content

Commit 54d278d

Browse files
committed
Move PowerState dataclass to typing.py
1 parent c32263e commit 54d278d

File tree

7 files changed

+57
-23
lines changed

7 files changed

+57
-23
lines changed

buildconfig/stubs/pygame/system.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List, Optional, TypedDict
22

3-
from pygame._data_classes import PowerState
3+
from pygame.typing import PowerState
44

55
class _InstructionSets(TypedDict):
66
ALTIVEC: bool

buildconfig/stubs/pygame/typing.pyi

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ __all__ = [
1414

1515
import sys
1616
from abc import abstractmethod
17-
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol
17+
from dataclasses import dataclass
18+
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, Optional
19+
1820

1921
if sys.version_info >= (3, 9):
2022
from os import PathLike as _PathProtocol
@@ -66,5 +68,28 @@ class _HasRectAttribute(Protocol):
6668
RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribute]
6769

6870

71+
@dataclass(frozen=True)
72+
class PowerState:
73+
battery_percent: Optional[int]
74+
battery_seconds: Optional[int]
75+
on_battery: bool
76+
no_battery: bool
77+
charging: bool
78+
charged: bool
79+
plugged_in: bool
80+
has_battery: bool
81+
82+
6983
# cleanup namespace
70-
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol
84+
del (
85+
sys,
86+
abstractmethod,
87+
IO,
88+
Callable,
89+
Tuple,
90+
Union,
91+
TypeVar,
92+
Protocol,
93+
Optional,
94+
dataclass,
95+
)

src_c/system.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ MODINIT_DEFINE(system)
261261
return NULL;
262262
}
263263

264-
PyObject *data_classes_module =
265-
PyImport_ImportModule("pygame._data_classes");
264+
PyObject *data_classes_module = PyImport_ImportModule("pygame.typing");
266265
if (!data_classes_module) {
267266
return NULL;
268267
}

src_py/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def PixelArray(surface): # pylint: disable=unused-argument
317317

318318
try:
319319
import pygame.system
320-
from pygame._data_classes import PowerState as power_state
320+
from pygame.typing import PowerState as power_state
321321

322322
power_state.__module__ = "pygame.system"
323323
del power_state

src_py/_data_classes.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

src_py/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
python_sources = files(
33
'__init__.py',
44
'_camera_opencv.py',
5-
'_data_classes.py',
65
'_debug.py',
76
'_sprite.py',
87
'camera.py',

src_py/typing.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
import sys
1616
from abc import abstractmethod
17-
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol
17+
from dataclasses import dataclass
18+
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, Optional
19+
1820

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

6870

71+
@dataclass(frozen=True)
72+
class PowerState:
73+
battery_percent: Optional[int]
74+
battery_seconds: Optional[int]
75+
on_battery: bool
76+
no_battery: bool
77+
charging: bool
78+
charged: bool
79+
plugged_in: bool
80+
has_battery: bool
81+
82+
6983
# cleanup namespace
70-
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol
84+
del (
85+
sys,
86+
abstractmethod,
87+
IO,
88+
Callable,
89+
Tuple,
90+
Union,
91+
TypeVar,
92+
Protocol,
93+
Optional,
94+
dataclass,
95+
)

0 commit comments

Comments
 (0)