Skip to content

Review SupportsInt and SupportsFloat usages in 3rd-party stubs #11003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
6 changes: 5 additions & 1 deletion stubs/PyAutoGUI/pyautogui/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
from _typeshed import ConvertibleToInt
from collections.abc import Callable, Iterable, Sequence
from datetime import datetime
from typing import NamedTuple, SupportsInt, TypeVar
Expand All @@ -19,7 +20,10 @@ from pyscreeze import (

_P = ParamSpec("_P")
_R = TypeVar("_R")
_NormalizeableXArg: TypeAlias = str | SupportsInt | Sequence[SupportsInt]
# Explicitly mentioning str despite being in the ConvertibleToInt Alias because it has a different meaning (filename on screen)
# Specifying non-None Y arg when X is a string or sequence raises an error
# TODO: This could be better represented through overloads
_NormalizeableXArg: TypeAlias = str | ConvertibleToInt | Sequence[ConvertibleToInt]

# Constants
KEY_NAMES: list[str]
Expand Down
9 changes: 5 additions & 4 deletions stubs/netaddr/netaddr/eui/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import ClassVar, SupportsInt, overload
from typing_extensions import Literal, Self, SupportsIndex
from _typeshed import ConvertibleToInt
from typing import ClassVar, overload
from typing_extensions import Literal, Self

from netaddr.core import DictDotLookup
from netaddr.ip import IPAddress
Expand Down Expand Up @@ -40,7 +41,7 @@ class EUI(BaseIdentifier):
@property
def value(self) -> int: ...
@value.setter
def value(self, value: str | SupportsInt | SupportsIndex) -> None: ...
def value(self, value: ConvertibleToInt) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good change, since the .value property is explicitly there in order to transform str, bytes objects etc. into int before they're stored on the EUI instance

@property
def dialect(self) -> type[mac_eui48 | eui64_base]: ...
@dialect.setter
Expand Down Expand Up @@ -77,7 +78,7 @@ class EUI(BaseIdentifier):
def bin(self) -> str: ...
def eui64(self) -> Self: ...
def modified_eui64(self) -> Self: ...
def ipv6(self, prefix: str | SupportsInt | SupportsIndex) -> IPAddress: ...
def ipv6(self, prefix: ConvertibleToInt) -> IPAddress: ...
def ipv6_link_local(self) -> IPAddress: ...
@property
def info(self) -> DictDotLookup: ...
Expand Down
10 changes: 5 additions & 5 deletions stubs/netaddr/netaddr/ip/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, Unused
from _typeshed import ConvertibleToInt, Incomplete, Unused
from abc import abstractmethod
from collections.abc import Iterable, Iterator
from typing import SupportsInt, overload
Expand Down Expand Up @@ -71,9 +71,9 @@ class IPAddress(BaseIP):
def ipv4(self) -> Self: ...
def ipv6(self, ipv4_compatible: bool = False) -> Self: ...
def format(self, dialect: type[ipv6_verbose] | None = None) -> str: ...
def __or__(self, other: str | SupportsInt | SupportsIndex) -> Self: ...
def __and__(self, other: str | SupportsInt | SupportsIndex) -> Self: ...
def __xor__(self, other: str | SupportsInt | SupportsIndex) -> Self: ...
def __or__(self, other: SupportsInt | SupportsIndex) -> Self: ...
def __and__(self, other: SupportsInt | SupportsIndex) -> Self: ...
def __xor__(self, other: SupportsInt | SupportsIndex) -> Self: ...
def __lshift__(self, numbits: int) -> Self: ...
def __rshift__(self, numbits: int) -> Self: ...
def __bool__(self) -> bool: ...
Expand Down Expand Up @@ -148,7 +148,7 @@ class IPRange(BaseIP, IPListMixin):
def cidrs(self) -> list[IPNetwork]: ...

def iter_unique_ips(*args: IPRange | _IPNetworkAddr) -> Iterator[IPAddress]: ...
def cidr_abbrev_to_verbose(abbrev_cidr: str | SupportsInt | SupportsIndex) -> str: ...
def cidr_abbrev_to_verbose(abbrev_cidr: ConvertibleToInt) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems reasonable to me; the function at runtime is deliberately very permissive in what it accepts

def cidr_merge(ip_addrs: Iterable[IPRange | _IPNetworkAddr]) -> list[IPNetwork]: ...
def cidr_exclude(target: _IPNetworkAddr, exclude: _IPNetworkAddr) -> list[IPNetwork]: ...
def cidr_partition(
Expand Down