Summary
In the latest version of ruff, the flake8-datetimez rules were added to the default rule set. As one of the maintainers of datetime in CPython and someone who has been writing about and giving talks about datetimes, I think this is extremely misguided.
I would keep DTZ002 (don't use datetime.datetime.today), DTZ003 and DTZ004 (don't use utc(now|fromtimestamp)), but that is it. DTZ901 (no datetime.min/datetime.max without a timezone) is probably the most bizarre one because it makes approximately zero sense to use a time zone with one of those: there are a bunch of weird edge cases when you do so, and they represent a time ~2000 years before time zones were invented and a time ~8000 years after the latest date where current time zone information is likely to be a good prediction of future offsets.
The main problem with all the other rules is that they fail to take into account that naïve time zones are the only real way to represent system local time in the datetime module. It is extremely common to want to work in the system local time zone. Having these rules on by default is going to teach people that you should do some very bad patterns like trying to guess what the system local time zone is, or picking a random time zone like "America/New_York" or something.
I strongly recommend making these rules opt-in.
Summary
In the latest version of
ruff, theflake8-datetimezrules were added to the default rule set. As one of the maintainers ofdatetimein CPython and someone who has been writing about and giving talks aboutdatetimes, I think this is extremely misguided.I would keep
DTZ002(don't usedatetime.datetime.today),DTZ003andDTZ004(don't useutc(now|fromtimestamp)), but that is it. DTZ901 (nodatetime.min/datetime.maxwithout a timezone) is probably the most bizarre one because it makes approximately zero sense to use a time zone with one of those: there are a bunch of weird edge cases when you do so, and they represent a time ~2000 years before time zones were invented and a time ~8000 years after the latest date where current time zone information is likely to be a good prediction of future offsets.The main problem with all the other rules is that they fail to take into account that naïve time zones are the only real way to represent system local time in the
datetimemodule. It is extremely common to want to work in the system local time zone. Having these rules on by default is going to teach people that you should do some very bad patterns like trying to guess what the system local time zone is, or picking a random time zone like "America/New_York" or something.I strongly recommend making these rules opt-in.