Skip to content

Commit e140464

Browse files
authored
[stdlib] Replace float with FloatInt (#16788)
Keep `float` in the following cases: - If it's already in an union with `int`. - Return types (also in compound return types). - Return types of `Callable` types. - Type arguments of base classes. - Type var constraints.
1 parent f6b4138 commit e140464

106 files changed

Lines changed: 1507 additions & 1447 deletions

File tree

Some content is hidden

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

‎stdlib/_interpchannels.pyi‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import structseq
1+
from _typeshed import FloatInt, structseq
22
from typing import Any, Final, Literal, SupportsIndex, final
33
from typing_extensions import Buffer, Self
44

@@ -76,8 +76,8 @@ def create(unboundop: Literal[1, 2, 3]) -> ChannelID: ...
7676
def destroy(cid: SupportsIndex) -> None: ...
7777
def list_all() -> list[ChannelID]: ...
7878
def list_interpreters(cid: SupportsIndex, *, send: bool) -> list[int]: ...
79-
def send(cid: SupportsIndex, obj: object, *, blocking: bool = True, timeout: float | None = None) -> None: ...
80-
def send_buffer(cid: SupportsIndex, obj: Buffer, *, blocking: bool = True, timeout: float | None = None) -> None: ...
79+
def send(cid: SupportsIndex, obj: object, *, blocking: bool = True, timeout: FloatInt | None = None) -> None: ...
80+
def send_buffer(cid: SupportsIndex, obj: Buffer, *, blocking: bool = True, timeout: FloatInt | None = None) -> None: ...
8181
def recv(cid: SupportsIndex, default: object = ...) -> tuple[Any, Literal[1, 2, 3]]: ...
8282
def close(cid: SupportsIndex, *, send: bool = False, recv: bool = False) -> None: ...
8383
def get_count(cid: SupportsIndex) -> int: ...

‎stdlib/_lsprof.pyi‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import structseq
1+
from _typeshed import FloatInt, structseq
22
from collections.abc import Callable
33
from types import CodeType
44
from typing import Any, Final, final
@@ -7,7 +7,7 @@ from typing_extensions import disjoint_base
77
@disjoint_base
88
class Profiler:
99
def __init__(
10-
self, timer: Callable[[], float] | None = None, timeunit: float = 0.0, subcalls: bool = True, builtins: bool = True
10+
self, timer: Callable[[], float] | None = None, timeunit: FloatInt = 0.0, subcalls: bool = True, builtins: bool = True
1111
) -> None: ...
1212
def getstats(self) -> list[profiler_entry]: ...
1313
def enable(self, subcalls: bool = True, builtins: bool = True) -> None: ...
@@ -20,8 +20,8 @@ class profiler_entry(structseq[Any], tuple[CodeType | str, int, int, float, floa
2020
code: CodeType | str
2121
callcount: int
2222
reccallcount: int
23-
totaltime: float
24-
inlinetime: float
23+
totaltime: FloatInt
24+
inlinetime: FloatInt
2525
calls: list[profiler_subentry]
2626

2727
@final
@@ -30,5 +30,5 @@ class profiler_subentry(structseq[Any], tuple[CodeType | str, int, int, float, f
3030
code: CodeType | str
3131
callcount: int
3232
reccallcount: int
33-
totaltime: float
34-
inlinetime: float
33+
totaltime: FloatInt
34+
inlinetime: FloatInt

‎stdlib/_queue.pyi‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import FloatInt
12
from types import GenericAlias
23
from typing import Any, Generic, TypeVar
34
from typing_extensions import disjoint_base
@@ -10,9 +11,9 @@ class Empty(Exception): ...
1011
class SimpleQueue(Generic[_T]):
1112
def __init__(self) -> None: ...
1213
def empty(self) -> bool: ...
13-
def get(self, block: bool = True, timeout: float | None = None) -> _T: ...
14+
def get(self, block: bool = True, timeout: FloatInt | None = None) -> _T: ...
1415
def get_nowait(self) -> _T: ...
15-
def put(self, item: _T, block: bool = True, timeout: float | None = None) -> None: ...
16+
def put(self, item: _T, block: bool = True, timeout: FloatInt | None = None) -> None: ...
1617
def put_nowait(self, item: _T) -> None: ...
1718
def qsize(self) -> int: ...
1819
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

‎stdlib/_remote_debugging.pyi‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from _typeshed import StrOrBytesPath, structseq
1+
from _typeshed import FloatInt, StrOrBytesPath, structseq
22
from collections.abc import Callable
33
from typing import Final, TypeAlias, final
44
from typing_extensions import Self
55

66
_Location: TypeAlias = tuple[int, int, int, int] | LocationInfo | None
77
_Frame: TypeAlias = tuple[str, _Location, str, int | None] | FrameInfo
8-
_Stats: TypeAlias = dict[str, int | float]
8+
_Stats: TypeAlias = dict[str, float | int]
99

1010
PROCESS_VM_READV_SUPPORTED: Final[int]
1111
THREAD_STATUS_GIL_REQUESTED: Final[int]
@@ -161,7 +161,12 @@ class BinaryWriter:
161161
def limit_reached(self) -> bool: ...
162162
def write_sample(self, stack_frames: list[InterpreterInfo], timestamp_us: int) -> None: ...
163163
def set_stats(
164-
self, /, duration_sec: float, sample_rate: float, error_rate: float | None = None, missed_samples: float | None = None
164+
self,
165+
/,
166+
duration_sec: FloatInt,
167+
sample_rate: FloatInt,
168+
error_rate: FloatInt | None = None,
169+
missed_samples: FloatInt | None = None,
165170
) -> None: ...
166171
def finalize(self) -> None: ...
167172
def close(self) -> None: ...

‎stdlib/_socket.pyi‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from _typeshed import ReadableBuffer, WriteableBuffer
2+
from _typeshed import FloatInt, ReadableBuffer, WriteableBuffer
33
from collections.abc import Iterable
44
from socket import error as error, gaierror as gaierror, herror as herror, timeout as timeout
55
from typing import Any, Final, SupportsIndex, TypeAlias, overload
@@ -906,7 +906,7 @@ class socket:
906906
) -> int: ...
907907

908908
def setblocking(self, flag: bool, /) -> None: ...
909-
def settimeout(self, value: float | None, /) -> None: ...
909+
def settimeout(self, value: FloatInt | None, /) -> None: ...
910910

911911
@overload
912912
def setsockopt(self, level: int, optname: int, value: int | ReadableBuffer, /) -> None: ...
@@ -948,7 +948,7 @@ def inet_ntop(address_family: int, packed_ip: ReadableBuffer, /) -> str: ...
948948
def getdefaulttimeout() -> float | None: ...
949949

950950
# F811: "Redefinition of unused `timeout`"
951-
def setdefaulttimeout(timeout: float | None, /) -> None: ...
951+
def setdefaulttimeout(timeout: FloatInt | None, /) -> None: ...
952952

953953
if sys.platform != "win32":
954954
def sethostname(name: str, /) -> None: ...

‎stdlib/_sqlite3.pyi‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from _typeshed import ReadableBuffer, StrOrBytesPath
2+
from _typeshed import FloatInt, ReadableBuffer, StrOrBytesPath
33
from collections.abc import Callable
44
from sqlite3 import (
55
Connection as Connection,
@@ -26,7 +26,7 @@ if sys.version_info >= (3, 11):
2626

2727
_T = TypeVar("_T")
2828
_ConnectionT = TypeVar("_ConnectionT", bound=Connection)
29-
_SqliteData: TypeAlias = str | ReadableBuffer | int | float | None
29+
_SqliteData: TypeAlias = str | ReadableBuffer | float | int | None
3030
_Adapter: TypeAlias = Callable[[_T], _SqliteData]
3131
_Converter: TypeAlias = Callable[[bytes], Any]
3232

@@ -227,7 +227,7 @@ if sys.version_info >= (3, 12):
227227
@overload
228228
def connect(
229229
database: StrOrBytesPath,
230-
timeout: float = 5.0,
230+
timeout: FloatInt = 5.0,
231231
detect_types: int = 0,
232232
isolation_level: _IsolationLevel = "DEFERRED",
233233
check_same_thread: bool = True,
@@ -239,7 +239,7 @@ if sys.version_info >= (3, 12):
239239
@overload
240240
def connect(
241241
database: StrOrBytesPath,
242-
timeout: float,
242+
timeout: FloatInt,
243243
detect_types: int,
244244
isolation_level: _IsolationLevel,
245245
check_same_thread: bool,
@@ -252,7 +252,7 @@ if sys.version_info >= (3, 12):
252252
@overload
253253
def connect(
254254
database: StrOrBytesPath,
255-
timeout: float = 5.0,
255+
timeout: FloatInt = 5.0,
256256
detect_types: int = 0,
257257
isolation_level: _IsolationLevel = "DEFERRED",
258258
check_same_thread: bool = True,
@@ -266,7 +266,7 @@ else:
266266
@overload
267267
def connect(
268268
database: StrOrBytesPath,
269-
timeout: float = 5.0,
269+
timeout: FloatInt = 5.0,
270270
detect_types: int = 0,
271271
isolation_level: _IsolationLevel = "DEFERRED",
272272
check_same_thread: bool = True,
@@ -276,7 +276,7 @@ else:
276276
@overload
277277
def connect(
278278
database: StrOrBytesPath,
279-
timeout: float,
279+
timeout: FloatInt,
280280
detect_types: int,
281281
isolation_level: _IsolationLevel,
282282
check_same_thread: bool,
@@ -287,7 +287,7 @@ else:
287287
@overload
288288
def connect(
289289
database: StrOrBytesPath,
290-
timeout: float = 5.0,
290+
timeout: FloatInt = 5.0,
291291
detect_types: int = 0,
292292
isolation_level: _IsolationLevel = "DEFERRED",
293293
check_same_thread: bool = True,

‎stdlib/_ssl.pyi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from _typeshed import ReadableBuffer, StrOrBytesPath
2+
from _typeshed import FloatInt, ReadableBuffer, StrOrBytesPath
33
from collections.abc import Callable
44
from ssl import (
55
SSLCertVerificationError as SSLCertVerificationError,
@@ -47,7 +47,7 @@ class _CertInfo(TypedDict):
4747
caIssuers: NotRequired[tuple[str, ...] | None]
4848
crlDistributionPoints: NotRequired[tuple[str, ...] | None]
4949

50-
def RAND_add(string: str | ReadableBuffer, entropy: float, /) -> None: ...
50+
def RAND_add(string: str | ReadableBuffer, entropy: FloatInt, /) -> None: ...
5151
def RAND_bytes(n: int, /) -> bytes: ...
5252

5353
if sys.version_info < (3, 12):

‎stdlib/_thread.pyi‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import signal
22
import sys
3-
from _typeshed import structseq
3+
from _typeshed import FloatInt, structseq
44
from collections.abc import Callable
55
from threading import Thread
66
from types import TracebackType
@@ -15,7 +15,7 @@ def _count() -> int: ...
1515

1616
@final
1717
class RLock:
18-
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
18+
def acquire(self, blocking: bool = True, timeout: FloatInt = -1) -> bool: ...
1919
def release(self) -> None: ...
2020
__enter__ = acquire
2121
def __exit__(
@@ -29,7 +29,7 @@ if sys.version_info >= (3, 13):
2929
class _ThreadHandle:
3030
ident: int
3131

32-
def join(self, timeout: float | None = None, /) -> None: ...
32+
def join(self, timeout: FloatInt | None = None, /) -> None: ...
3333
def is_done(self) -> bool: ...
3434
def _set_done(self) -> None: ...
3535

@@ -39,11 +39,11 @@ if sys.version_info >= (3, 13):
3939

4040
@final
4141
class lock:
42-
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
42+
def acquire(self, blocking: bool = True, timeout: FloatInt = -1) -> bool: ...
4343
def release(self) -> None: ...
4444
def locked(self) -> bool: ...
4545
@deprecated("Obsolete synonym. Use `acquire()` instead.")
46-
def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ... # undocumented
46+
def acquire_lock(self, blocking: bool = True, timeout: FloatInt = -1) -> bool: ... # undocumented
4747
@deprecated("Obsolete synonym. Use `release()` instead.")
4848
def release_lock(self) -> None: ... # undocumented
4949
@deprecated("Obsolete synonym. Use `locked()` instead.")
@@ -57,11 +57,11 @@ if sys.version_info >= (3, 13):
5757
else:
5858
@final
5959
class LockType:
60-
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
60+
def acquire(self, blocking: bool = True, timeout: FloatInt = -1) -> bool: ...
6161
def release(self) -> None: ...
6262
def locked(self) -> bool: ...
6363
@deprecated("Obsolete synonym. Use `acquire()` instead.")
64-
def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ... # undocumented
64+
def acquire_lock(self, blocking: bool = True, timeout: FloatInt = -1) -> bool: ... # undocumented
6565
@deprecated("Obsolete synonym. Use `release()` instead.")
6666
def release_lock(self) -> None: ... # undocumented
6767
@deprecated("Obsolete synonym. Use `locked()` instead.")
@@ -93,7 +93,7 @@ def allocate() -> LockType: ... # undocumented
9393
def get_ident() -> int: ...
9494
def stack_size(size: int = 0, /) -> int: ...
9595

96-
TIMEOUT_MAX: Final[float]
96+
TIMEOUT_MAX: Final[FloatInt]
9797

9898
def get_native_id() -> int: ... # only available on some platforms
9999

‎stdlib/_typeshed/__init__.pyi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Unused: TypeAlias = object # stable
5858
# for more information.
5959
MaybeNone: TypeAlias = Any # stable
6060

61-
# typeshed-internal type aliases to facilitate transition from
61+
# typeshed-internal type alias to facilitate transition from
6262
# `float` to either `float | int` or `float`. When you encounter this type
6363
# alias, you are encouraged to replace it with the correct type. Please don't
6464
# use it outside typeshed.

‎stdlib/antigravity.pyi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from _typeshed import ReadableBuffer
1+
from _typeshed import FloatInt, ReadableBuffer
22

3-
def geohash(latitude: float, longitude: float, datedow: ReadableBuffer) -> None: ...
3+
def geohash(latitude: FloatInt, longitude: FloatInt, datedow: ReadableBuffer) -> None: ...

0 commit comments

Comments
 (0)