Skip to content

Commit 40f5a82

Browse files
authored
[Python] Fix library type stubs for parse_int32/64 and from_integer (#4310)
1 parent 842471d commit 40f5a82

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/Fable.Cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
* [Python] Fix library type stubs for parse_int32/64 and from_integer (by @dbrattli)
1213
* [Python] Fix missing type parameters on generic methods (by @dbrattli)
1314
* [JS/TS] Fix #4305 DateTimeOffset.Now returns wrong time (by @ncave)
1415

src/Fable.Compiler/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
* [Python] Fix library type stubs for parse_int32/64 and from_integer (by @dbrattli)
1213
* [Python] Fix missing type parameters on generic methods (by @dbrattli)
1314
* [JS/TS] Fix #4305 DateTimeOffset.Now returns wrong time (by @ncave)
1415

src/fable-library-py/fable_library/core/ints.pyi

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,21 @@ def parse_int32(
194194
string: str,
195195
style: int,
196196
unsigned: bool,
197+
bitsize: int,
197198
radix: int = 10,
198199
) -> Int32:
199200
"""
200201
Parses a string representation of a 32-bit integer with F#-compatible semantics.
201-
This function matches the behavior of int32.py parse function exactly.
202202
203203
Args:
204204
string: The string to parse
205205
style: NumberStyles flags controlling parsing behavior
206206
unsigned: Whether to treat the result as unsigned (u32)
207+
bitsize: The bit width of the target type (8, 16, or 32)
207208
radix: Default radix to use (defaults to 10)
208209
209210
Returns:
210-
The parsed integer value as int
211+
The parsed integer value
211212
212213
Raises:
213214
ValueError: If the string is not in a valid format or value is out of range
@@ -218,20 +219,21 @@ def parse_int64(
218219
string: str,
219220
style: int,
220221
unsigned: bool,
222+
bitsize: int,
221223
radix: int = 10,
222224
) -> Int64:
223225
"""
224226
Parses a string representation of a 64-bit integer with F#-compatible semantics.
225-
This function matches the behavior of long.py parse function exactly.
226227
227228
Args:
228229
string: The string to parse
229230
style: NumberStyles flags controlling parsing behavior
230231
unsigned: Whether to treat the result as unsigned (u64)
232+
bitsize: The bit width (64)
231233
radix: Default radix to use (defaults to 10)
232234
233235
Returns:
234-
The parsed integer value as int
236+
The parsed integer value
235237
236238
Raises:
237239
ValueError: If the string is not in a valid format or value is out of range
@@ -242,8 +244,8 @@ def try_parse_int32(
242244
string: str,
243245
style: int,
244246
unsigned: bool,
247+
bitsize: int,
245248
def_value: Any,
246-
radix: int = 10,
247249
) -> bool:
248250
"""
249251
Attempts to parse a 32-bit integer with F#-style try semantics.
@@ -252,8 +254,8 @@ def try_parse_int32(
252254
string: The string to parse
253255
style: NumberStyles flags controlling parsing behavior
254256
unsigned: Whether to treat the result as unsigned (u32)
257+
bitsize: The bit width of the target type (8, 16, or 32)
255258
def_value: Python object reference to store the result on success
256-
radix: Default radix to use (defaults to 10)
257259
258260
Returns:
259261
True if parsing succeeded, False otherwise
@@ -264,8 +266,8 @@ def try_parse_int64(
264266
string: str,
265267
style: int,
266268
unsigned: bool,
269+
bitsize: int,
267270
def_value: Any,
268-
radix: int = 10,
269271
) -> bool:
270272
"""
271273
Attempts to parse a 64-bit integer with F#-style try semantics.
@@ -274,8 +276,8 @@ def try_parse_int64(
274276
string: The string to parse
275277
style: NumberStyles flags controlling parsing behavior
276278
unsigned: Whether to treat the result as unsigned (u64)
279+
bitsize: The bit width (64)
277280
def_value: Python object reference to store the result on success
278-
radix: Default radix to use (defaults to 10)
279281
280282
Returns:
281283
True if parsing succeeded, False otherwise

src/fable-library-py/fable_library/long.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ def to_number(value: SupportsFloat | SupportsInt) -> float64:
255255

256256

257257
@overload
258-
def from_integer(value: int, unsigned: Literal[True], kind: int) -> uint64: ...
258+
def from_integer(value: SupportsInt, unsigned: Literal[True], kind: int) -> uint64: ...
259259

260260

261261
@overload
262-
def from_integer(value: int, unsigned: Literal[False], kind: int) -> int64: ...
262+
def from_integer(value: SupportsInt, unsigned: Literal[False], kind: int) -> int64: ...
263263

264264

265-
def from_integer(value: int, unsigned: bool | None = None, kind: int | None = None) -> int64 | uint64:
265+
def from_integer(value: SupportsInt, unsigned: bool | None = None, kind: int | None = None) -> int64 | uint64:
266266
if unsigned:
267267
return uint64(value)
268268
else:

0 commit comments

Comments
 (0)