A pytz time zone is passed as tzinfo, which gives a wrong offset

tx0/python:pytz-tzinfo-argumentdefaultwarningbug

What it finds

datetime(2024, 5, 1, tzinfo=pytz.timezone("Europe/Berlin")): a pytz zone passed as tzinfo, to datetime, time or a replace method, uses the zone's first entry in the time zone database, its local mean time, which is off by minutes from the real offset (+00:53 for Berlin). pytz zones are meant to be applied with zone.localize(naive); zoneinfo.ZoneInfo works as tzinfo directly.

From the rule's source, pytz_tzinfo_argument.rs.

Example from the rule's tests
import datetimeimport pytz  def stamp():    berlin = pytz.timezone("Europe/Berlin")    a = datetime.datetime(2024, 5, 1, tzinfo=pytz.timezone("Europe/Berlin"))tx0 reports: a pytz zone as tzinfo uses its local mean time, which is off by minutes    b = berlin.localize(datetime.datetime(2024, 5, 1))    c = datetime.datetime(2024, 5, 1, tzinfo=datetime.timezone.utc)    d = a.replace(tzinfo=pytz.timezone("Asia/Tokyo"))tx0 reports: a pytz zone as tzinfo    e = datetime.time(12, tzinfo=(pytz.timezone("UTC")))tx0 reports: a pytz zone as tzinfo    f = pytz.timezone("UTC").localize(datetime.datetime(2024, 1, 1))    return a, b, c, d, e, f
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/python:pytz-tzinfo-argument" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:pytz-tzinfo-argument] reason="..."

tx0 explain tx0/python:pytz-tzinfo-argument shows the same in the terminal. Found a false positive? Report it.