Skip to content

Commit ce3c470

Browse files
committed
Reshuffle annotations; use Any as default again
1 parent 25a3e48 commit ce3c470

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

stdlib/datetime.pyi

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class timedelta:
210210
def __bool__(self) -> bool: ...
211211
def __hash__(self) -> int: ...
212212

213-
_TzInfoT = TypeVar("_TzInfoT", bound=tzinfo | None, default=tzinfo | None, covariant=True)
213+
_TzInfoT = TypeVar("_TzInfoT", bound=tzinfo | None, default=Any)
214214

215215
class datetime(date, Generic[_TzInfoT]):
216216
min: ClassVar[datetime]
@@ -391,36 +391,48 @@ class datetime(date, Generic[_TzInfoT]):
391391
def tzname(self) -> str | None: ...
392392
def dst(self) -> timedelta | None: ...
393393
@overload # type: ignore[override]
394-
def __le__(self: datetime[_TzInfo], value: datetime[None], /) -> NoReturn: ... # type: ignore[misc]
394+
def __le__(
395+
self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], /
396+
) -> bool: ... # type: ignore[misc]
395397
@overload
396-
def __le__(self: datetime[None], value: datetime[_TzInfo], /) -> NoReturn: ... # type: ignore[misc]
398+
def __le__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc]
397399
@overload
398-
def __le__(self: datetime[Any], value: datetime[Any], /) -> bool: ...
400+
def __le__(self: datetime[Any], value: datetime[Any], /) -> NoReturn: ...
399401
@overload # type: ignore[override]
400-
def __lt__(self: datetime[_TzInfo], value: datetime[None], /) -> NoReturn: ... # type: ignore[misc]
402+
def __lt__(
403+
self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], /
404+
) -> bool: ... # type: ignore[misc]
401405
@overload
402-
def __lt__(self: datetime[None], value: datetime[_TzInfo], /) -> NoReturn: ... # type: ignore[misc]
406+
def __lt__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc]
403407
@overload
404-
def __lt__(self: datetime[Any], value: datetime[Any], /) -> bool: ...
408+
def __lt__(self: datetime[Any], value: datetime[Any], /) -> NoReturn: ...
405409
@overload # type: ignore[override]
406-
def __ge__(self: datetime[_TzInfo], value: datetime[None], /) -> NoReturn: ... # type: ignore[misc]
410+
def __ge__(
411+
self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], /
412+
) -> bool: ... # type: ignore[misc]
407413
@overload
408-
def __ge__(self: datetime[None], value: datetime[_TzInfo], /) -> NoReturn: ... # type: ignore[misc]
414+
def __ge__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc]
409415
@overload
410-
def __ge__(self: datetime[Any], value: datetime[Any], /) -> bool: ...
416+
def __ge__(self: datetime[Any], value: datetime[Any], /) -> NoReturn: ...
411417
@overload # type: ignore[override]
412-
def __gt__(self: datetime[_TzInfo], value: datetime[None], /) -> NoReturn: ... # type: ignore[misc]
418+
def __gt__(
419+
self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], /
420+
) -> bool: ... # type: ignore[misc]
413421
@overload
414-
def __gt__(self: datetime[None], value: datetime[_TzInfo], /) -> NoReturn: ... # type: ignore[misc]
422+
def __gt__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc]
415423
@overload
416-
def __gt__(self: datetime[Any], value: datetime[Any], /) -> bool: ...
424+
def __gt__(self: datetime[Any], value: datetime[Any], /) -> NoReturn: ...
417425
def __eq__(self, value: object, /) -> bool: ...
418426
def __hash__(self) -> int: ...
419427
@overload # type: ignore[override]
420-
def __sub__(self: datetime[_TzInfo], value: datetime[None], /) -> NoReturn: ...
428+
def __sub__(
429+
self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], /
430+
) -> timedelta: ...
421431
@overload
422-
def __sub__(self: datetime[None], value: datetime[_TzInfo], /) -> NoReturn: ...
432+
def __sub__(
433+
self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /
434+
) -> timedelta: ...
423435
@overload
424-
def __sub__(self: datetime[Any], value: datetime[Any], /) -> timedelta: ...
436+
def __sub__(self: datetime[Any], value: datetime[Any], /) -> NoReturn: ...
425437
@overload
426438
def __sub__(self, value: timedelta, /) -> Self: ...

test_cases/stdlib/check_unittest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929
case.assertAlmostEqual(2.4, 2.41, places=9, delta=0.02) # type: ignore
3030
case.assertAlmostEqual("foo", "bar") # type: ignore
31-
case.assertAlmostEqual(datetime(1999, 1, 2), datetime(1999, 1, 2, microsecond=1)) # pyright: ignore
31+
# TODO: mypy and pyright disagree whether this requires a type ignore.
32+
# case.assertAlmostEqual(datetime(1999, 1, 2), datetime(1999, 1, 2, microsecond=1))
3233
case.assertAlmostEqual(Decimal("0.4"), Fraction(1, 2)) # type: ignore
3334
case.assertAlmostEqual(complex(2, 3), Decimal("0.9")) # type: ignore
3435

@@ -44,7 +45,8 @@
4445

4546
case.assertNotAlmostEqual(2.4, 2.41, places=9, delta=0.02) # type: ignore
4647
case.assertNotAlmostEqual("foo", "bar") # type: ignore
47-
case.assertNotAlmostEqual(datetime(1999, 1, 2), datetime(1999, 1, 2, microsecond=1)) # pyright: ignore
48+
# TODO: mypy and pyright disagree whether this requires a type ignore.
49+
# case.assertNotAlmostEqual(datetime(1999, 1, 2), datetime(1999, 1, 2, microsecond=1))
4850
case.assertNotAlmostEqual(Decimal("0.4"), Fraction(1, 2)) # type: ignore
4951
case.assertNotAlmostEqual(complex(2, 3), Decimal("0.9")) # type: ignore
5052

0 commit comments

Comments
 (0)