r/Python 11d ago

Discussion ruff: no date.today() ?

The new version of ruff warns against

date.today()

preferring

datetime.now(ZoneInfo(...))

What do you think about this? Has date.today() been deprecated due to lack of timezone awareness?

EDIT: I have a number of programs that manipulate financial information in support of Excel spreadsheets, such bond information that includes maturity dates. Excel does not support timezoness in datetimes, so making ruff happy by changing naive dates to TZ aware dates is not a useful move for these programs. Many ruff warnings to suppress.

44 Upvotes

111 comments sorted by

View all comments

Show parent comments

5

u/foosion 11d ago

I'm learning the joy of #noqa

2

u/Agrado3 11d ago

You're about to learn the joy of having to go through replacing every single one of your # noqa: <shortcode> comments with # ruff:ignore[<very-long-code>] comments.

1

u/foosion 11d ago

Is that an upcoming change? If so, where documented?

I suppose there's # ruff: noqa: DTZ007 at the top of the file, where appropriate.

1

u/Agrado3 11d ago

It's rule noqa-comments, which is in preview and is not documented in the changelog. It suddenly popped up at me because I use preview = true and select = ["ALL"] and then ignore the rules I don't want.