Skip to content

Commit 9f86f10

Browse files
committed
fix float <: CanRound2[int, float]
1 parent b611197 commit 9f86f10

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

optype/_core/_can.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ def __round__(self, /) -> _T_int_co: ...
14591459

14601460
@runtime_checkable
14611461
class CanRound2(Protocol[_T_int_contra, _T_float_co]):
1462-
def __round__(self, /, ndigits: _T_int_contra) -> _T_float_co: ...
1462+
def __round__(self, ndigits: _T_int_contra, /) -> _T_float_co: ...
14631463

14641464

14651465
@runtime_checkable
@@ -1472,7 +1472,7 @@ class CanRound(
14721472
@override
14731473
def __round__(self, /) -> _T_int_co: ...
14741474
@overload
1475-
def __round__(self, /, ndigits: _T_int_contra) -> _T_float_co: ...
1475+
def __round__(self, ndigits: _T_int_contra, /) -> _T_float_co: ...
14761476

14771477

14781478
@runtime_checkable

tests/core/test_can.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,18 @@ def test_can_same_self(cls: type) -> None:
352352

353353
assert members_same == members_self
354354
assert members_same == members_base
355+
356+
357+
def test_can_round_float() -> None:
358+
# https://github.com/jorenham/optype/issues/596
359+
360+
x: float = 1 / 137
361+
362+
r1: op.CanRound1[int] = x
363+
assert isinstance(r1, op.CanRound1)
364+
365+
r2: op.CanRound2[int, float] = x
366+
assert isinstance(r2, op.CanRound2)
367+
368+
r: op.CanRound[int, int, float] = x
369+
assert isinstance(r, op.CanRound)

0 commit comments

Comments
 (0)