Skip to content

Commit 2f13e66

Browse files
authored
Require Python 3.12 (#37)
1 parent cf1701e commit 2f13e66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+282
-2009
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "python-stubs"
33
version = "0.0.0"
4-
requires-python = ">=3.9"
4+
requires-python = ">=3.12"
55

66
[dependency-groups]
77
tests = [

stubs/__builtins__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from typing_extensions import reveal_type as reveal_type
1+
from typing import reveal_type as reveal_type

stubs/netfields-stubs/fields.pyi

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from _typeshed import Unused
22
from collections.abc import Callable, Iterable
33
from ipaddress import IPv4Interface, IPv4Network, IPv6Interface, IPv6Network
4-
from typing import Literal, TypeVar, overload
4+
from typing import Literal, overload
55

66
from django.db.models.expressions import Combinable
77
from django.db.models.fields import Field, _ErrorMessagesToOverride, _ValidatorCallable
@@ -11,9 +11,8 @@ from netfields.forms import CidrAddressFormField, InetAddressFormField, NoPrefix
1111

1212
NET_OPERATORS: dict[str, str]
1313
NET_TEXT_OPERATORS: list[str]
14-
_I = TypeVar("_I", bound=IPv4Interface | IPv6Interface | None)
1514

16-
class InetAddressField(Field[_I | Combinable, _I]):
15+
class InetAddressField[I: IPv4Interface | IPv6Interface | None](Field[I | Combinable, I]):
1716
@overload
1817
def __new__(
1918
cls,
@@ -25,14 +24,14 @@ class InetAddressField(Field[_I | Combinable, _I]):
2524
blank: bool = False,
2625
null: Literal[False] = False,
2726
db_index: bool = False,
28-
default: _I | Callable[[], _I] | None = ...,
27+
default: I | Callable[[], I] | None = ...,
2928
editable: bool = True,
3029
auto_created: bool = False,
3130
serialize: bool = True,
3231
unique_for_date: str | None = None,
3332
unique_for_month: str | None = None,
3433
unique_for_year: str | None = None,
35-
choices: Iterable[tuple[_I, str] | tuple[str, Iterable[tuple[_I, str]]]] | None = None,
34+
choices: Iterable[tuple[I, str] | tuple[str, Iterable[tuple[I, str]]]] | None = None,
3635
help_text: str = "",
3736
db_column: str | None = None,
3837
db_tablespace: str | None = None,
@@ -52,14 +51,14 @@ class InetAddressField(Field[_I | Combinable, _I]):
5251
*,
5352
null: Literal[True],
5453
db_index: bool = False,
55-
default: _I | Callable[[], _I] = ...,
54+
default: I | Callable[[], I] = ...,
5655
editable: bool = True,
5756
auto_created: bool = False,
5857
serialize: bool = True,
5958
unique_for_date: str | None = None,
6059
unique_for_month: str | None = None,
6160
unique_for_year: str | None = None,
62-
choices: Iterable[tuple[_I, str] | tuple[str, Iterable[tuple[_I, str]]]] | None = None,
61+
choices: Iterable[tuple[I, str] | tuple[str, Iterable[tuple[I, str]]]] | None = None,
6362
help_text: str = "",
6463
db_column: str | None = None,
6564
db_tablespace: str | None = None,
@@ -70,9 +69,7 @@ class InetAddressField(Field[_I | Combinable, _I]):
7069
def python_type(self) -> Callable[..., IPv4Interface | IPv6Interface]: ...
7170
def form_class(self) -> type[InetAddressFormField | NoPrefixInetAddressFormField]: ...
7271

73-
_N = TypeVar("_N", bound=IPv4Network | IPv6Network | None)
74-
75-
class CidrAddressField(Field[_N | Combinable, _N]):
72+
class CidrAddressField[N: IPv4Network | IPv6Network | None](Field[N | Combinable, N]):
7673
@overload
7774
def __new__(
7875
cls,
@@ -84,14 +81,14 @@ class CidrAddressField(Field[_N | Combinable, _N]):
8481
blank: bool = False,
8582
null: Literal[False] = False,
8683
db_index: bool = False,
87-
default: _N | Callable[[], _N] | None = ...,
84+
default: N | Callable[[], N] | None = ...,
8885
editable: bool = True,
8986
auto_created: bool = False,
9087
serialize: bool = True,
9188
unique_for_date: str | None = None,
9289
unique_for_month: str | None = None,
9390
unique_for_year: str | None = None,
94-
choices: Iterable[tuple[_N, str] | tuple[str, Iterable[tuple[_N, str]]]] | None = None,
91+
choices: Iterable[tuple[N, str] | tuple[str, Iterable[tuple[N, str]]]] | None = None,
9592
help_text: str = "",
9693
db_column: str | None = None,
9794
db_tablespace: str | None = None,
@@ -110,14 +107,14 @@ class CidrAddressField(Field[_N | Combinable, _N]):
110107
*,
111108
null: Literal[True],
112109
db_index: bool = False,
113-
default: _N | Callable[[], _N] = ...,
110+
default: N | Callable[[], N] = ...,
114111
editable: bool = True,
115112
auto_created: bool = False,
116113
serialize: bool = True,
117114
unique_for_date: str | None = None,
118115
unique_for_month: str | None = None,
119116
unique_for_year: str | None = None,
120-
choices: Iterable[tuple[_N, str] | tuple[str, Iterable[tuple[_N, str]]]] | None = None,
117+
choices: Iterable[tuple[N, str] | tuple[str, Iterable[tuple[N, str]]]] | None = None,
121118
help_text: str = "",
122119
db_column: str | None = None,
123120
db_tablespace: str | None = None,
@@ -127,9 +124,7 @@ class CidrAddressField(Field[_N | Combinable, _N]):
127124
def python_type(self) -> Callable[..., IPv4Network | IPv6Network]: ...
128125
def form_class(self) -> type[CidrAddressFormField]: ...
129126

130-
_E = TypeVar("_E", bound=EUI | None)
131-
132-
class MACAddressField(Field[_E | Combinable, _E]):
127+
class MACAddressField[E: EUI | None](Field[E | Combinable, E]):
133128
@overload
134129
def __new__(
135130
cls,
@@ -141,14 +136,14 @@ class MACAddressField(Field[_E | Combinable, _E]):
141136
blank: bool = False,
142137
null: Literal[False] = False,
143138
db_index: bool = False,
144-
default: _E | Callable[[], _E] | None = ...,
139+
default: E | Callable[[], E] | None = ...,
145140
editable: bool = True,
146141
auto_created: bool = False,
147142
serialize: bool = True,
148143
unique_for_date: str | None = None,
149144
unique_for_month: str | None = None,
150145
unique_for_year: str | None = None,
151-
choices: Iterable[tuple[_E, str] | tuple[str, Iterable[tuple[_E, str]]]] | None = None,
146+
choices: Iterable[tuple[E, str] | tuple[str, Iterable[tuple[E, str]]]] | None = None,
152147
help_text: str = "",
153148
db_column: str | None = None,
154149
db_tablespace: str | None = None,
@@ -167,14 +162,14 @@ class MACAddressField(Field[_E | Combinable, _E]):
167162
*,
168163
null: Literal[True],
169164
db_index: bool = False,
170-
default: _E | Callable[[], _E] = ...,
165+
default: E | Callable[[], E] = ...,
171166
editable: bool = True,
172167
auto_created: bool = False,
173168
serialize: bool = True,
174169
unique_for_date: str | None = None,
175170
unique_for_month: str | None = None,
176171
unique_for_year: str | None = None,
177-
choices: Iterable[tuple[_E, str] | tuple[str, Iterable[tuple[_E, str]]]] | None = None,
172+
choices: Iterable[tuple[E, str] | tuple[str, Iterable[tuple[E, str]]]] | None = None,
178173
help_text: str = "",
179174
db_column: str | None = None,
180175
db_tablespace: str | None = None,
@@ -184,7 +179,7 @@ class MACAddressField(Field[_E | Combinable, _E]):
184179
def from_db_value(self, value: str, expression: Unused, connection: Unused, *args: Unused) -> EUI | None: ...
185180
def get_db_prep_value(self, value: int | str | EUI | None, connection: Unused, prepared: bool = False) -> str: ...
186181

187-
class MACAddress8Field(Field[_E | Combinable, _E]):
182+
class MACAddress8Field[E: EUI | None](Field[E | Combinable, E]):
188183
@overload
189184
def __new__(
190185
cls,
@@ -196,14 +191,14 @@ class MACAddress8Field(Field[_E | Combinable, _E]):
196191
blank: bool = False,
197192
null: Literal[False] = False,
198193
db_index: bool = False,
199-
default: _E | Callable[[], _E] | None = ...,
194+
default: E | Callable[[], E] | None = ...,
200195
editable: bool = True,
201196
auto_created: bool = False,
202197
serialize: bool = True,
203198
unique_for_date: str | None = None,
204199
unique_for_month: str | None = None,
205200
unique_for_year: str | None = None,
206-
choices: Iterable[tuple[_E, str] | tuple[str, Iterable[tuple[_E, str]]]] | None = None,
201+
choices: Iterable[tuple[E, str] | tuple[str, Iterable[tuple[E, str]]]] | None = None,
207202
help_text: str = "",
208203
db_column: str | None = None,
209204
db_tablespace: str | None = None,
@@ -222,14 +217,14 @@ class MACAddress8Field(Field[_E | Combinable, _E]):
222217
*,
223218
null: Literal[True],
224219
db_index: bool = False,
225-
default: _E | Callable[[], _E] = ...,
220+
default: E | Callable[[], E] = ...,
226221
editable: bool = True,
227222
auto_created: bool = False,
228223
serialize: bool = True,
229224
unique_for_date: str | None = None,
230225
unique_for_month: str | None = None,
231226
unique_for_year: str | None = None,
232-
choices: Iterable[tuple[_E, str] | tuple[str, Iterable[tuple[_E, str]]]] | None = None,
227+
choices: Iterable[tuple[E, str] | tuple[str, Iterable[tuple[E, str]]]] | None = None,
233228
help_text: str = "",
234229
db_column: str | None = None,
235230
db_tablespace: str | None = None,

stubs/netfields-stubs/managers.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
from typing import TypeVar
2-
from typing_extensions import Literal
1+
from typing import Literal
32

43
from django.db import models
54

6-
_T = TypeVar("_T", bound=models.Model)
7-
8-
class NetManager(models.Manager[_T]):
5+
class NetManager[M: models.Model](models.Manager[M]):
96
use_for_related_fields: Literal[True]

stubs/netfields-stubs/rest_framework.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ from _typeshed import Incomplete, Unused
22
from collections.abc import Callable, Sequence
33
from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network
44
from typing import Any
5-
from typing_extensions import TypeAlias
65

76
from netaddr import EUI
87
from rest_framework.fields import Field, empty
98
from rest_framework.serializers import ModelSerializer
109

11-
_IPAddress: TypeAlias = IPv4Address | IPv6Address
12-
_IPNetwork: TypeAlias = IPv4Network | IPv6Network
13-
_InetDefaultInitial: TypeAlias = _IPAddress | None | Callable[[], _IPAddress | None] | type[empty] # type: ignore[valid-type] # pyright: ignore[reportInvalidTypeForm]
10+
type _IPAddress = IPv4Address | IPv6Address
11+
type _IPNetwork = IPv4Network | IPv6Network
12+
type _InetDefaultInitial = _IPAddress | None | Callable[[], _IPAddress | None] | type[empty] # type: ignore[valid-type] # pyright: ignore[reportInvalidTypeForm]
1413

1514
class InetAddressField(Field[_IPAddress | None, _IPAddress | int | str | None, str | None, Incomplete]):
1615
store_prefix: bool

stubs/pandapower-stubs/_typing.pyi

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
from collections.abc import Collection, Iterable, Mapping, MutableMapping
2-
from typing import Any, Protocol, SupportsFloat, SupportsIndex, TypedDict, TypeVar, type_check_only
3-
from typing_extensions import TypeAlias
2+
from typing import Any, Protocol, SupportsFloat, SupportsIndex, TypedDict, type_check_only
43

54
import numpy as np
65

7-
_T = TypeVar("_T")
8-
_G = TypeVar("_G", bound=np.generic)
9-
_Generic_co = TypeVar("_Generic_co", covariant=True, bound=np.generic)
10-
116
# Wide primitives for input types
12-
Bool: TypeAlias = bool | np.bool
13-
Int: TypeAlias = SupportsIndex
14-
Float: TypeAlias = SupportsFloat | Int
7+
type Bool = bool | np.bool
8+
type Int = SupportsIndex
9+
type Float = SupportsFloat | Int
1510

1611
# Vector-related
17-
ScalarOrVector: TypeAlias = _T | Collection[_T]
18-
Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_G]]
19-
Array2D: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_G]]
12+
type ScalarOrVector[T] = T | Collection[T]
13+
type Array1D[G: np.generic] = np.ndarray[tuple[int], np.dtype[G]]
14+
type Array2D[G: np.generic] = np.ndarray[tuple[int, int], np.dtype[G]]
2015

21-
class SupportsArray(Protocol[_Generic_co]):
22-
def __array__(self) -> np.ndarray[Any, np.dtype[_Generic_co]]: ...
16+
class SupportsArray[G: np.generic](Protocol):
17+
def __array__(self) -> np.ndarray[Any, np.dtype[G]]: ...
2318

24-
VectorLike: TypeAlias = Collection[_T] | SupportsArray[_G]
25-
FloatVectorLike: TypeAlias = VectorLike[Float, np.floating | np.integer | np.bool]
19+
type VectorLike[T, G: np.generic] = Collection[T] | SupportsArray[G]
20+
type FloatVectorLike = VectorLike[Float, np.floating | np.integer | np.bool]
2621

2722
# File I/O related
2823
@type_check_only
@@ -44,7 +39,7 @@ class SupportsGeoInterface(Protocol):
4439
@property
4540
def __geo_interface__(self) -> dict[str, Any]: ... # values are arbitrary
4641

47-
ConvertibleToCRS: TypeAlias = str | int | tuple[str, str] | list[str] | dict[str, Any] | SupportsToWkt
42+
type ConvertibleToCRS = str | int | tuple[str, str] | list[str] | dict[str, Any] | SupportsToWkt
4843

4944
from pandapower.auxiliary import pandapowerNet # noqa: E402
5045

stubs/pandapower-stubs/auxiliary.pyi

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from collections.abc import Iterable, Mapping, MutableMapping
3-
from typing import Any, Final, Literal, NoReturn, TypeVar, overload
4-
from typing_extensions import Self, deprecated
3+
from typing import Any, Final, Literal, NoReturn, Self, overload
4+
from typing_extensions import deprecated
55

66
import geopandas as gpd
77
import numpy as np
@@ -12,25 +12,23 @@ from shapely.geometry.base import BaseGeometry
1212
from pandapower._typing import Array2D, Float, Int
1313
from pandapower.std_types import _StdTypes
1414

15-
_T = TypeVar("_T")
16-
1715
def log_to_level(msg: str, passed_logger: logging.Logger, level: str) -> None: ...
1816
def version_check(package_name: str, level: str = "UserWarning", ignore_not_installed: bool = False) -> None: ...
1917
def soft_dependency_error(fct_name: str, required_packages: str | Iterable[str]) -> NoReturn: ...
20-
def warn_and_fix_parameter_renaming(
18+
def warn_and_fix_parameter_renaming[T](
2119
old_parameter_name: str,
2220
new_parameter_name: str,
23-
new_parameter: _T,
24-
default_value: _T,
21+
new_parameter: T,
22+
default_value: T,
2523
category: type[Warning] = ...,
2624
**kwargs: Any,
27-
) -> _T: ...
25+
) -> T: ...
2826

29-
class ADict(dict[str, _T], MutableMapping[str, _T]):
30-
def __setattr__(self, key: str, value: _T) -> None: ...
27+
class ADict[T](dict[str, T], MutableMapping[str, T]):
28+
def __setattr__(self, key: str, value: T) -> None: ...
3129
def __delattr__(self, key: str, force: bool = False) -> None: ...
32-
def __call__(self, key: str) -> _T: ...
33-
def __getattr__(self, key: str) -> _T: ...
30+
def __call__(self, key: str) -> T: ...
31+
def __getattr__(self, key: str) -> T: ...
3432
def __deepcopy__(self, memo: dict[int, Any] | None) -> Self: ...
3533

3634
class pandapowerNet(ADict[pd.DataFrame]):
@@ -167,7 +165,7 @@ class OPFNotConverged(ppException): ...
167165
def get_indices(
168166
selection: Iterable[Int], lookup: Mapping[Int, Int] | Mapping[str, Mapping[Int, Int]], fused_indices: bool = True
169167
) -> NDArray[np.int64]: ...
170-
def ensure_iterability(var: _T | Iterable[_T], len_: Int | None = None) -> Iterable[_T]: ...
168+
def ensure_iterability[T](var: T | Iterable[T], len_: Int | None = None) -> Iterable[T]: ...
171169
def read_from_net(
172170
net: pandapowerNet,
173171
element: str,

stubs/pandapower-stubs/build_bus.pyi

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from _typeshed import Incomplete
22
from collections.abc import Collection
3-
from typing import Literal, TypeVar
3+
from typing import Literal
44

55
import numpy as np
66
from numpy.typing import NDArray
77

88
from pandapower._typing import Array1D, Bool, Float, Int, ScalarOrVector
99
from pandapower.auxiliary import pandapowerNet
1010

11-
_T = TypeVar("_T")
12-
1311
def ds_find(ar, bus): ...
1412
def ds_union(ar, bus1: Int, bus2: Int, bus_is_pv, bus_is_active, merged_bus) -> None: ...
1513
def ds_create(
@@ -29,10 +27,10 @@ def create_bus_lookup_numba(
2927
net: pandapowerNet, bus_index: Collection[Int], bus_is_idx: ScalarOrVector[Int]
3028
) -> tuple[Array1D[np.int64], Array1D[np.bool]]: ...
3129

32-
class DisjointSet(dict[_T, _T]):
33-
def add(self, item: _T) -> None: ...
34-
def find(self, item: _T) -> _T: ...
35-
def union(self, item1: _T, item2: _T) -> None: ...
30+
class DisjointSet[T](dict[T, T]):
31+
def add(self, item: T) -> None: ...
32+
def find(self, item: T) -> T: ...
33+
def union(self, item1: T, item2: T) -> None: ...
3634

3735
def create_consecutive_bus_lookup(bus_index: Collection[Int]) -> Array1D[np.int64]: ...
3836
def create_bus_lookup_numpy(

stubs/pandapower-stubs/control/util/characteristic.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from _typeshed import Incomplete
22
from collections.abc import Iterable
3-
from typing import Any
4-
from typing_extensions import Literal, Self
3+
from typing import Any, Literal, Self
54

65
import numpy as np
76
from numpy.typing import ArrayLike

stubs/pandapower-stubs/converter/cim/cim_classes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing_extensions import Self
2+
from typing import Self
33

44
import pandas as pd
55

0 commit comments

Comments
 (0)