3 ms·
Python should use different types to represent datetimes with a timezone and those without. class Datetime: pass class NaiveDatetime:
by neillyons 3y ago
Python should use different types to represent datetimes with a timezone and those without.
class Datetime:
pass
class NaiveDatetime:
pass
That way you can annotate functions properly.
def timezone(datetime: Datetime) -> ...:
This is how Elixir does it. So much easier to understand as a newcomer.
https://hexdocs.pm/elixir/DateTime.html https://hexdocs.pm/elixir/DateTime.html
https://hexdocs.pm/elixir/NaiveDateTime.html https://hexdocs.pm/elixir/NaiveDateTime.html
- llbeansandrice 3y agoThis seems like the blatantly obvious path to me. Perhaps that needs to be dealt with in a major version release tho. TZ naive and TZ datetimes are needed and it’s important to chose the correct one.
- dikei 3y agoSo is Java with `LocalDateTime` and `ZonedDateTime`, a very useful example of making your typesystem work for you.