Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "python-stubs"
version = "0.0.0"
requires-python = ">=3.9"
requires-python = ">=3.12"

[dependency-groups]
tests = [
Expand Down
2 changes: 1 addition & 1 deletion stubs/__builtins__.pyi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from typing_extensions import reveal_type as reveal_type
from typing import reveal_type as reveal_type
47 changes: 21 additions & 26 deletions stubs/netfields-stubs/fields.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from _typeshed import Unused
from collections.abc import Callable, Iterable
from ipaddress import IPv4Interface, IPv4Network, IPv6Interface, IPv6Network
from typing import Literal, TypeVar, overload
from typing import Literal, overload

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

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

class InetAddressField(Field[_I | Combinable, _I]):
class InetAddressField[I: IPv4Interface | IPv6Interface | None](Field[I | Combinable, I]):
@overload
def __new__(
cls,
Expand All @@ -25,14 +24,14 @@ class InetAddressField(Field[_I | Combinable, _I]):
blank: bool = False,
null: Literal[False] = False,
db_index: bool = False,
default: _I | Callable[[], _I] | None = ...,
default: I | Callable[[], I] | None = ...,
editable: bool = True,
auto_created: bool = False,
serialize: bool = True,
unique_for_date: str | None = None,
unique_for_month: str | None = None,
unique_for_year: str | None = None,
choices: Iterable[tuple[_I, str] | tuple[str, Iterable[tuple[_I, str]]]] | None = None,
choices: Iterable[tuple[I, str] | tuple[str, Iterable[tuple[I, str]]]] | None = None,
help_text: str = "",
db_column: str | None = None,
db_tablespace: str | None = None,
Expand All @@ -52,14 +51,14 @@ class InetAddressField(Field[_I | Combinable, _I]):
*,
null: Literal[True],
db_index: bool = False,
default: _I | Callable[[], _I] = ...,
default: I | Callable[[], I] = ...,
editable: bool = True,
auto_created: bool = False,
serialize: bool = True,
unique_for_date: str | None = None,
unique_for_month: str | None = None,
unique_for_year: str | None = None,
choices: Iterable[tuple[_I, str] | tuple[str, Iterable[tuple[_I, str]]]] | None = None,
choices: Iterable[tuple[I, str] | tuple[str, Iterable[tuple[I, str]]]] | None = None,
help_text: str = "",
db_column: str | None = None,
db_tablespace: str | None = None,
Expand All @@ -70,9 +69,7 @@ class InetAddressField(Field[_I | Combinable, _I]):
def python_type(self) -> Callable[..., IPv4Interface | IPv6Interface]: ...
def form_class(self) -> type[InetAddressFormField | NoPrefixInetAddressFormField]: ...

_N = TypeVar("_N", bound=IPv4Network | IPv6Network | None)

class CidrAddressField(Field[_N | Combinable, _N]):
class CidrAddressField[N: IPv4Network | IPv6Network | None](Field[N | Combinable, N]):
@overload
def __new__(
cls,
Expand All @@ -84,14 +81,14 @@ class CidrAddressField(Field[_N | Combinable, _N]):
blank: bool = False,
null: Literal[False] = False,
db_index: bool = False,
default: _N | Callable[[], _N] | None = ...,
default: N | Callable[[], N] | None = ...,
editable: bool = True,
auto_created: bool = False,
serialize: bool = True,
unique_for_date: str | None = None,
unique_for_month: str | None = None,
unique_for_year: str | None = None,
choices: Iterable[tuple[_N, str] | tuple[str, Iterable[tuple[_N, str]]]] | None = None,
choices: Iterable[tuple[N, str] | tuple[str, Iterable[tuple[N, str]]]] | None = None,
help_text: str = "",
db_column: str | None = None,
db_tablespace: str | None = None,
Expand All @@ -110,14 +107,14 @@ class CidrAddressField(Field[_N | Combinable, _N]):
*,
null: Literal[True],
db_index: bool = False,
default: _N | Callable[[], _N] = ...,
default: N | Callable[[], N] = ...,
editable: bool = True,
auto_created: bool = False,
serialize: bool = True,
unique_for_date: str | None = None,
unique_for_month: str | None = None,
unique_for_year: str | None = None,
choices: Iterable[tuple[_N, str] | tuple[str, Iterable[tuple[_N, str]]]] | None = None,
choices: Iterable[tuple[N, str] | tuple[str, Iterable[tuple[N, str]]]] | None = None,
help_text: str = "",
db_column: str | None = None,
db_tablespace: str | None = None,
Expand All @@ -127,9 +124,7 @@ class CidrAddressField(Field[_N | Combinable, _N]):
def python_type(self) -> Callable[..., IPv4Network | IPv6Network]: ...
def form_class(self) -> type[CidrAddressFormField]: ...

_E = TypeVar("_E", bound=EUI | None)

class MACAddressField(Field[_E | Combinable, _E]):
class MACAddressField[E: EUI | None](Field[E | Combinable, E]):
@overload
def __new__(
cls,
Expand All @@ -141,14 +136,14 @@ class MACAddressField(Field[_E | Combinable, _E]):
blank: bool = False,
null: Literal[False] = False,
db_index: bool = False,
default: _E | Callable[[], _E] | None = ...,
default: E | Callable[[], E] | None = ...,
editable: bool = True,
auto_created: bool = False,
serialize: bool = True,
unique_for_date: str | None = None,
unique_for_month: str | None = None,
unique_for_year: str | None = None,
choices: Iterable[tuple[_E, str] | tuple[str, Iterable[tuple[_E, str]]]] | None = None,
choices: Iterable[tuple[E, str] | tuple[str, Iterable[tuple[E, str]]]] | None = None,
help_text: str = "",
db_column: str | None = None,
db_tablespace: str | None = None,
Expand All @@ -167,14 +162,14 @@ class MACAddressField(Field[_E | Combinable, _E]):
*,
null: Literal[True],
db_index: bool = False,
default: _E | Callable[[], _E] = ...,
default: E | Callable[[], E] = ...,
editable: bool = True,
auto_created: bool = False,
serialize: bool = True,
unique_for_date: str | None = None,
unique_for_month: str | None = None,
unique_for_year: str | None = None,
choices: Iterable[tuple[_E, str] | tuple[str, Iterable[tuple[_E, str]]]] | None = None,
choices: Iterable[tuple[E, str] | tuple[str, Iterable[tuple[E, str]]]] | None = None,
help_text: str = "",
db_column: str | None = None,
db_tablespace: str | None = None,
Expand All @@ -184,7 +179,7 @@ class MACAddressField(Field[_E | Combinable, _E]):
def from_db_value(self, value: str, expression: Unused, connection: Unused, *args: Unused) -> EUI | None: ...
def get_db_prep_value(self, value: int | str | EUI | None, connection: Unused, prepared: bool = False) -> str: ...

class MACAddress8Field(Field[_E | Combinable, _E]):
class MACAddress8Field[E: EUI | None](Field[E | Combinable, E]):
@overload
def __new__(
cls,
Expand All @@ -196,14 +191,14 @@ class MACAddress8Field(Field[_E | Combinable, _E]):
blank: bool = False,
null: Literal[False] = False,
db_index: bool = False,
default: _E | Callable[[], _E] | None = ...,
default: E | Callable[[], E] | None = ...,
editable: bool = True,
auto_created: bool = False,
serialize: bool = True,
unique_for_date: str | None = None,
unique_for_month: str | None = None,
unique_for_year: str | None = None,
choices: Iterable[tuple[_E, str] | tuple[str, Iterable[tuple[_E, str]]]] | None = None,
choices: Iterable[tuple[E, str] | tuple[str, Iterable[tuple[E, str]]]] | None = None,
help_text: str = "",
db_column: str | None = None,
db_tablespace: str | None = None,
Expand All @@ -222,14 +217,14 @@ class MACAddress8Field(Field[_E | Combinable, _E]):
*,
null: Literal[True],
db_index: bool = False,
default: _E | Callable[[], _E] = ...,
default: E | Callable[[], E] = ...,
editable: bool = True,
auto_created: bool = False,
serialize: bool = True,
unique_for_date: str | None = None,
unique_for_month: str | None = None,
unique_for_year: str | None = None,
choices: Iterable[tuple[_E, str] | tuple[str, Iterable[tuple[_E, str]]]] | None = None,
choices: Iterable[tuple[E, str] | tuple[str, Iterable[tuple[E, str]]]] | None = None,
help_text: str = "",
db_column: str | None = None,
db_tablespace: str | None = None,
Expand Down
7 changes: 2 additions & 5 deletions stubs/netfields-stubs/managers.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from typing import TypeVar
from typing_extensions import Literal
from typing import Literal

from django.db import models

_T = TypeVar("_T", bound=models.Model)

class NetManager(models.Manager[_T]):
class NetManager[M: models.Model](models.Manager[M]):
use_for_related_fields: Literal[True]
7 changes: 3 additions & 4 deletions stubs/netfields-stubs/rest_framework.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ from _typeshed import Incomplete, Unused
from collections.abc import Callable, Sequence
from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network
from typing import Any
from typing_extensions import TypeAlias

from netaddr import EUI
from rest_framework.fields import Field, empty
from rest_framework.serializers import ModelSerializer

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

class InetAddressField(Field[_IPAddress | None, _IPAddress | int | str | None, str | None, Incomplete]):
store_prefix: bool
Expand Down
29 changes: 12 additions & 17 deletions stubs/pandapower-stubs/_typing.pyi
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
from collections.abc import Collection, Iterable, Mapping, MutableMapping
from typing import Any, Protocol, SupportsFloat, SupportsIndex, TypedDict, TypeVar, type_check_only
from typing_extensions import TypeAlias
from typing import Any, Protocol, SupportsFloat, SupportsIndex, TypedDict, type_check_only

import numpy as np

_T = TypeVar("_T")
_G = TypeVar("_G", bound=np.generic)
_Generic_co = TypeVar("_Generic_co", covariant=True, bound=np.generic)

# Wide primitives for input types
Bool: TypeAlias = bool | np.bool
Int: TypeAlias = SupportsIndex
Float: TypeAlias = SupportsFloat | Int
type Bool = bool | np.bool
type Int = SupportsIndex
type Float = SupportsFloat | Int

# Vector-related
ScalarOrVector: TypeAlias = _T | Collection[_T]
Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_G]]
Array2D: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_G]]
type ScalarOrVector[T] = T | Collection[T]
type Array1D[G: np.generic] = np.ndarray[tuple[int], np.dtype[G]]
type Array2D[G: np.generic] = np.ndarray[tuple[int, int], np.dtype[G]]

class SupportsArray(Protocol[_Generic_co]):
def __array__(self) -> np.ndarray[Any, np.dtype[_Generic_co]]: ...
class SupportsArray[G: np.generic](Protocol):
def __array__(self) -> np.ndarray[Any, np.dtype[G]]: ...

VectorLike: TypeAlias = Collection[_T] | SupportsArray[_G]
FloatVectorLike: TypeAlias = VectorLike[Float, np.floating | np.integer | np.bool]
type VectorLike[T, G: np.generic] = Collection[T] | SupportsArray[G]
type FloatVectorLike = VectorLike[Float, np.floating | np.integer | np.bool]

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

ConvertibleToCRS: TypeAlias = str | int | tuple[str, str] | list[str] | dict[str, Any] | SupportsToWkt
type ConvertibleToCRS = str | int | tuple[str, str] | list[str] | dict[str, Any] | SupportsToWkt

from pandapower.auxiliary import pandapowerNet # noqa: E402

Expand Down
24 changes: 11 additions & 13 deletions stubs/pandapower-stubs/auxiliary.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from collections.abc import Iterable, Mapping, MutableMapping
from typing import Any, Final, Literal, NoReturn, TypeVar, overload
from typing_extensions import Self, deprecated
from typing import Any, Final, Literal, NoReturn, Self, overload
from typing_extensions import deprecated

import geopandas as gpd
import numpy as np
Expand All @@ -12,25 +12,23 @@ from shapely.geometry.base import BaseGeometry
from pandapower._typing import Array2D, Float, Int
from pandapower.std_types import _StdTypes

_T = TypeVar("_T")

def log_to_level(msg: str, passed_logger: logging.Logger, level: str) -> None: ...
def version_check(package_name: str, level: str = "UserWarning", ignore_not_installed: bool = False) -> None: ...
def soft_dependency_error(fct_name: str, required_packages: str | Iterable[str]) -> NoReturn: ...
def warn_and_fix_parameter_renaming(
def warn_and_fix_parameter_renaming[T](
old_parameter_name: str,
new_parameter_name: str,
new_parameter: _T,
default_value: _T,
new_parameter: T,
default_value: T,
category: type[Warning] = ...,
**kwargs: Any,
) -> _T: ...
) -> T: ...

class ADict(dict[str, _T], MutableMapping[str, _T]):
def __setattr__(self, key: str, value: _T) -> None: ...
class ADict[T](dict[str, T], MutableMapping[str, T]):
def __setattr__(self, key: str, value: T) -> None: ...
def __delattr__(self, key: str, force: bool = False) -> None: ...
def __call__(self, key: str) -> _T: ...
def __getattr__(self, key: str) -> _T: ...
def __call__(self, key: str) -> T: ...
def __getattr__(self, key: str) -> T: ...
def __deepcopy__(self, memo: dict[int, Any] | None) -> Self: ...

class pandapowerNet(ADict[pd.DataFrame]):
Expand Down Expand Up @@ -167,7 +165,7 @@ class OPFNotConverged(ppException): ...
def get_indices(
selection: Iterable[Int], lookup: Mapping[Int, Int] | Mapping[str, Mapping[Int, Int]], fused_indices: bool = True
) -> NDArray[np.int64]: ...
def ensure_iterability(var: _T | Iterable[_T], len_: Int | None = None) -> Iterable[_T]: ...
def ensure_iterability[T](var: T | Iterable[T], len_: Int | None = None) -> Iterable[T]: ...
def read_from_net(
net: pandapowerNet,
element: str,
Expand Down
12 changes: 5 additions & 7 deletions stubs/pandapower-stubs/build_bus.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from _typeshed import Incomplete
from collections.abc import Collection
from typing import Literal, TypeVar
from typing import Literal

import numpy as np
from numpy.typing import NDArray

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

_T = TypeVar("_T")

def ds_find(ar, bus): ...
def ds_union(ar, bus1: Int, bus2: Int, bus_is_pv, bus_is_active, merged_bus) -> None: ...
def ds_create(
Expand All @@ -29,10 +27,10 @@ def create_bus_lookup_numba(
net: pandapowerNet, bus_index: Collection[Int], bus_is_idx: ScalarOrVector[Int]
) -> tuple[Array1D[np.int64], Array1D[np.bool]]: ...

class DisjointSet(dict[_T, _T]):
def add(self, item: _T) -> None: ...
def find(self, item: _T) -> _T: ...
def union(self, item1: _T, item2: _T) -> None: ...
class DisjointSet[T](dict[T, T]):
def add(self, item: T) -> None: ...
def find(self, item: T) -> T: ...
def union(self, item1: T, item2: T) -> None: ...

def create_consecutive_bus_lookup(bus_index: Collection[Int]) -> Array1D[np.int64]: ...
def create_bus_lookup_numpy(
Expand Down
3 changes: 1 addition & 2 deletions stubs/pandapower-stubs/control/util/characteristic.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from typing import Any
from typing_extensions import Literal, Self
from typing import Any, Literal, Self

import numpy as np
from numpy.typing import ArrayLike
Expand Down
2 changes: 1 addition & 1 deletion stubs/pandapower-stubs/converter/cim/cim_classes.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing_extensions import Self
from typing import Self

import pandas as pd

Expand Down
5 changes: 2 additions & 3 deletions stubs/pandapower-stubs/create.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import Collection, Mapping
from typing import Any, Literal
from typing_extensions import TypeAlias

import numpy as np
import pandas as pd
Expand All @@ -9,8 +8,8 @@ from numpy.typing import DTypeLike
from pandapower._typing import Array1D, Bool, Float, Int, ScalarOrVector
from pandapower.auxiliary import pandapowerNet

_CostElementType: TypeAlias = Literal["gen", "sgen", "ext_grid", "load", "dcline", "storage"]
_SGenGeneratorType: TypeAlias = Literal["current_source", "async", "async_doubly_fed"]
type _CostElementType = Literal["gen", "sgen", "ext_grid", "load", "dcline", "storage"]
type _SGenGeneratorType = Literal["current_source", "async", "async_doubly_fed"]

def create_empty_network(name: str = "", f_hz: Float = 50.0, sn_mva: Float = 1, add_stdtypes: Bool = True) -> pandapowerNet: ...
def create_bus(
Expand Down
Loading