Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion expected_mypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@ tryit.py:53: note: Got:
tryit.py:53: note: def timetz(self) -> Time[timezone]
tryit.py:53: note: tzinfo: expected "None", got "timezone"
tryit.py:56: error: Incompatible types in assignment (expression has type "NaiveTime", variable has type "DateTime[timezone]") [assignment]
Found 10 errors in 1 file (checked 1 source file)
tryit.py:58: error: Unsupported operand types for - ("NaiveDateTime" and "AwareDateTime") [operator]
tryit.py:58: note: Following member(s) of "AwareDateTime" have conflicts:
tryit.py:58: note: Expected:
tryit.py:58: note: def timetz(self) -> Time[None]
tryit.py:58: note: Got:
tryit.py:58: note: def timetz(self) -> Time[tzinfo]
tryit.py:58: note: tzinfo: expected "None", got "tzinfo"
tryit.py:59: error: Unsupported operand types for - ("AwareDateTime" and "NaiveDateTime") [operator]
tryit.py:59: note: Following member(s) of "NaiveDateTime" have conflicts:
tryit.py:59: note: Expected:
tryit.py:59: note: def timetz(self) -> Time[tzinfo]
tryit.py:59: note: Got:
tryit.py:59: note: def timetz(self) -> Time[None]
tryit.py:59: note: tzinfo: expected "tzinfo", got "None"
Found 12 errors in 1 file (checked 1 source file)
16 changes: 15 additions & 1 deletion expected_mypy_37.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ tryit.py:53: note: Got:
tryit.py:53: note: def timetz(self) -> Time[timezone]
tryit.py:53: note: tzinfo: expected "None", got "timezone"
tryit.py:56: error: Incompatible types in assignment (expression has type "NaiveTime", variable has type "DateTime[timezone]") [assignment]
Found 8 errors in 1 file (checked 1 source file)
tryit.py:58: error: Unsupported operand types for - ("NaiveDateTime" and "AwareDateTime") [operator]
tryit.py:58: note: Following member(s) of "AwareDateTime" have conflicts:
tryit.py:58: note: Expected:
tryit.py:58: note: def timetz(self) -> Time[None]
tryit.py:58: note: Got:
tryit.py:58: note: def timetz(self) -> Time[tzinfo]
tryit.py:58: note: tzinfo: expected "None", got "tzinfo"
tryit.py:59: error: Unsupported operand types for - ("AwareDateTime" and "NaiveDateTime") [operator]
tryit.py:59: note: Following member(s) of "NaiveDateTime" have conflicts:
tryit.py:59: note: Expected:
tryit.py:59: note: def timetz(self) -> Time[tzinfo]
tryit.py:59: note: Got:
tryit.py:59: note: def timetz(self) -> Time[None]
tryit.py:59: note: tzinfo: expected "tzinfo", got "None"
Found 10 errors in 1 file (checked 1 source file)
5 changes: 4 additions & 1 deletion src/datetype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,10 @@ def __gt__(self: Self, __other: Self) -> bool: ...
def __sub__(self: Self, __other: _timedelta) -> Self: ...

@overload
def __sub__(self: DTSelf, __other: DTSelf) -> _timedelta: ...
def __sub__(self: DateTime[None], __other: DateTime[None]) -> _timedelta: ...

@overload
def __sub__(self: DateTime[_tzinfo], __other: DateTime[_tzinfo]) -> _timedelta: ...

def __add__(self: Self, __other: _timedelta) -> Self: ...

Expand Down
24 changes: 23 additions & 1 deletion src/datetype/test/test_datetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
from sys import version_info
from unittest import TestCase, skipIf

from datetype import AwareDateTime, NaiveDateTime, NaiveTime, Time, aware, naive
from datetype import (
AwareDateTime,
NaiveDateTime,
NaiveTime,
Time,
aware,
naive,
DateTime,
)

TEST_DATA = (Path(__file__) / "..").resolve()
while not (TEST_DATA / ".git").is_dir():
Expand Down Expand Up @@ -87,3 +95,17 @@ def test_none_aware(self) -> None:
awareified = aware(stddt)
self.assertIs(awareified.tzinfo, zi)
self.assertEqual(awareified.tzinfo.dst(stddt), timedelta(0))

@skipIf(version_info < (3, 9), "ZoneInfo")
def test_differing_zone_subtract(self) -> None:
from zoneinfo import ZoneInfo

zi = ZoneInfo("US/Pacific")
stddt = datetime(2025, 2, 13, 15, 35, 13, 574354, tzinfo=zi)
inutc = stddt.astimezone(timezone.utc)

dtzi: DateTime[ZoneInfo] = aware(stddt, ZoneInfo)
dttz: DateTime[timezone] = aware(inutc, timezone)

self.assertEqual(dtzi - dttz, timedelta(0))
self.assertEqual(dttz - dtzi, timedelta(0))
5 changes: 5 additions & 0 deletions tryit.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@
is_aware: DateTime[timezone] = a.astimezone(None)

not_aware_method_time: DateTime[timezone] = a.time() # nope; actually naive

x - y # error; naive & aware are incompatible
y - x # also error
y - is_aware # ok
is_aware - y # ok