Skip to content

Commit e86fb2c

Browse files
committed
Move PowerState dataclass to typing.py
1 parent 5893923 commit e86fb2c

File tree

7 files changed

+35
-21
lines changed

7 files changed

+35
-21
lines changed

buildconfig/stubs/pygame/system.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from typing import Optional, TypedDict
77

8-
from pygame._data_classes import PowerState
8+
from pygame.typing import PowerState
99

1010
class _InstructionSets(TypedDict):
1111
ALTIVEC: bool

buildconfig/stubs/pygame/typing.pyi

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ __all__ = [
1414

1515
from abc import abstractmethod
1616
from collections.abc import Callable
17+
from dataclasses import dataclass
1718
from os import PathLike as _PathProtocol
18-
from typing import IO, Protocol, TypeVar, Union
19+
from typing import IO, Protocol, TypeVar, Union, Optional
1920

2021
from pygame.color import Color
2122
from pygame.rect import FRect, Rect
@@ -62,6 +63,18 @@ RectLike = Union[
6263
]
6364

6465

66+
@dataclass(frozen=True)
67+
class PowerState:
68+
battery_percent: Optional[int]
69+
battery_seconds: Optional[int]
70+
on_battery: bool
71+
no_battery: bool
72+
charging: bool
73+
charged: bool
74+
plugged_in: bool
75+
has_battery: bool
76+
77+
6578
# cleanup namespace
6679
del (
6780
abstractmethod,
@@ -73,4 +86,6 @@ del (
7386
Union,
7487
TypeVar,
7588
Protocol,
89+
Optional,
90+
dataclass,
7691
)

src_c/system.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ MODINIT_DEFINE(system)
283283
return NULL;
284284
}
285285

286-
PyObject *data_classes_module =
287-
PyImport_ImportModule("pygame._data_classes");
286+
PyObject *data_classes_module = PyImport_ImportModule("pygame.typing");
288287
if (!data_classes_module) {
289288
return NULL;
290289
}

src_py/__init__.py

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

331331
try:
332332
import pygame.system
333-
from pygame._data_classes import PowerState as power_state
333+
from pygame.typing import PowerState as power_state
334334

335335
power_state.__module__ = "pygame.system"
336336
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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
from abc import abstractmethod
1616
from collections.abc import Callable
17+
from dataclasses import dataclass
1718
from os import PathLike as _PathProtocol
18-
from typing import IO, Protocol, TypeVar, Union
19+
from typing import IO, Protocol, TypeVar, Union, Optional
1920

2021
from pygame.color import Color
2122
from pygame.rect import FRect, Rect
@@ -62,6 +63,18 @@ def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ...
6263
]
6364

6465

66+
@dataclass(frozen=True)
67+
class PowerState:
68+
battery_percent: Optional[int]
69+
battery_seconds: Optional[int]
70+
on_battery: bool
71+
no_battery: bool
72+
charging: bool
73+
charged: bool
74+
plugged_in: bool
75+
has_battery: bool
76+
77+
6578
# cleanup namespace
6679
del (
6780
abstractmethod,
@@ -73,4 +86,6 @@ def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ...
7386
Union,
7487
TypeVar,
7588
Protocol,
89+
Optional,
90+
dataclass,
7691
)

0 commit comments

Comments
 (0)