Skip to content

datetime-utc-alias

Pythonstyleno fixdefault: offpython/ruff

Reports datetime.timezone.utc, also written timezone.utc after an import, when the target_version has datetime.UTC (3.11 and later).

datetime.UTC is the shorter name of the same object, added in Python 3.11. One spelling of UTC in a code base is easier to search for.

To fix, write datetime.UTC.

Reported
...
pass
import datetime
x = datetime.timezone.utc
...
...
python:
lint:
rules:
datetime-utc-alias: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line datetime-utc-alias in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff UP017 full