You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add import datetime as dt as a conventional alias #28604
Reacted by Thibaut Decombe, Tom Kuson, Hugo van Kemenade, Adrián Garnier Artiñano, Guilhem Saurel, David Kane, Dan Redding, Avasam, Alex Waygood, Irene Adler💜 and 1 more
I just meant that we could include the modification to the default aliases value in our v0.17 release, which will also include other breaking changes related to 3.15.
I guess we could also make the default value dependent on the configured Python version, but that's not what I had in mind at the time.
On second thoughts, it would be best not to tie this change to intrpreter version, since there’s nothing inherent about Python 3.15 affecting the alias. Making linter fixes/errors appear when you upgrade Ruff, rather than when you upgrade Python, is less confusing.
Reacted by Hugo van Kemenade, Brent Westbrook and Alex Waygood
Unfortunately it seems there is no simple way to 'opt-out' of this breaking change. I have a lot of code that uses dt as a 'timestep' argument or variable, so this default rule is causing naming collisions.
Is there any way to revert the rule requiring import datetime as dt in my ruff config, without having to fully redefine the other defaults in aliases? While there is the extend-aliases option, there is not an option to remove one of the aliases from the defaults.
The rationale is given here in the issue, and this change was made in a breaking Ruff release. If you want to revert to the old behavior, you can configurealiases or extend-aliases, as also described above.
Thanks for the response. I do feel the cost / benefit tradeoff here is questionable. I'd like to ask you to reconsider and revert the datetime default.
The "import datetime as dt" was a new convention, not as established as numpy or pandas. The cPython change was only for the examples in their docs, not a style ruling, not a PEP 8 requirement. Even that was contested, for concerns about churns. The PR author also noted: "You can still import datetime if you prefer."
I don't think an examples-only docs edit should be treated as an endorsement by the wider Python community.
Almost every ICN user with "import datetime" now has to change either code or config.
We enabled ICN for its well-established flake8 conventions, not expecting newer, debatable ones to be added to the defaults.
Reverting now breaks no one.
Reacted by Jakub Kuczys, Tom Young, Morgan Lokhorst and Stephen
Speaking as a user of Ruff, I like the new default. It means I no longer have to add the alias myself. I think the alias makes reading and writing Python code a more pleasant experience, especially for those unfamiliar with the nuances of the datetime library. I'd be favour of including the alias by default even if the CPython docs didn't bless it (it seems sufficiently popular to me regardless).
If we're being comparative, import datetime as dt is probably the alias with the strongest motivation of all the default set. I've always found import numpy as np a pretty funny convention, it only saves three characters per name!
I also don't share your interpretation of the discussion under the CPython pull request. Regardless, CPython and the official documentation has very different priorities and motivations to that of a third-party linter.
Can't say that I've seen this convention before it got added as an alias to Ruff but have seen people use dt as a name for the variable storing a datetime.datetime object which this is incompatible with.
More broadly, I don't know how I feel about such a simple change to docs.python.org now making it possible to appeal to authority when arguing for this new linter default.
Not sure why people complaining - datetime.datetime was always confusing and annoying (compare with from pathlib import Path). So, definitely good thing and LLMs can help to fix existing code with minimal effort.
Not sure why people complaining - datetime.datetime was always confusing and annoying (compare with from pathlib import Path). So, definitely good thing and LLMs can help to fix existing code with minimal effort.
The fact is this is not currently a widely used 'convention', even if it might have some advantages.
Unlike other common aliases, such as np or pd, dt is a much more common abbreviation which is often used in existing code in ways that cannot be simply changed. For instance, if it is used as a kwarg in a well established api func(..., *, dt: float): ..., this collides with import datetime as dt and cannot be changed without breaking downstream code.
We can debate the merits of adopting a new convention, but there is no point in being dismissive for the disruption that a new rule like this causes.
Reacted by Jakub Kuczys, Morgan Lokhorst and Stephen
used as a kwarg in a well established api func(..., *, dt: float): ..., this collides with import datetime as dt and cannot be changed without breaking downstream code
if it's a public API then yes, but if it's something internal I am sure any modern LLM will fix it cheaply enough.
Activity
ntBre commentedon Sep 15, 2026
I think this is technically a breaking change, but we have a minor release coming up for Python 3.15 and can include it in that.
adamchainz commentedon Sep 17, 2026
Are you saying you'll include it for Python 3.15+ only? That seems like a reasonable decision, given that's when the docs start recommend the alias.
ntBre commentedon Sep 17, 2026
I just meant that we could include the modification to the default
aliasesvalue in our v0.17 release, which will also include other breaking changes related to 3.15.I guess we could also make the default value dependent on the configured Python version, but that's not what I had in mind at the time.
adamchainz commentedon Sep 18, 2026
Right, I see.
On second thoughts, it would be best not to tie this change to intrpreter version, since there’s nothing inherent about Python 3.15 affecting the alias. Making linter fixes/errors appear when you upgrade Ruff, rather than when you upgrade Python, is less confusing.
hugovk commentedon Sep 19, 2026
We backported python/cpython#145315 to all bugfix versions (back to 3.13), so the 3.15 distinction isn't special.
[`flake8-import-conventions`] Add `datetime as dt` as a conventional …
[`flake8-import-conventions`] Add `datetime as dt` as a conventional …
[`flake8-import-conventions`] Add `datetime as dt` as a conventional …
[`flake8-import-conventions`] Add `datetime as dt` as a conventional …
[`flake8-import-conventions`] Add `datetime as dt` as a conventional …
[`flake8-import-conventions`] Add `datetime as dt` as a conventional …
[`flake8-import-conventions`] Add `datetime as dt` as a conventional …
kohlerjl commentedon Oct 10, 2026
Unfortunately it seems there is no simple way to 'opt-out' of this breaking change. I have a lot of code that uses
dtas a 'timestep' argument or variable, so this default rule is causing naming collisions.Is there any way to revert the rule requiring
import datetime as dtin my ruff config, without having to fully redefine the other defaults inaliases? While there is theextend-aliasesoption, there is not an option to remove one of the aliases from the defaults.ntBre commentedon Oct 13, 2026
It's a bit of a hack (#17097), but you can actually use
extend-aliasesto override one of the defaults. Configuringwill allow you to use
import datetime. Otherwise, yes, fully definingaliasesis the best fix.xhan80 commentedon Oct 16, 2026
What's the rationale for doing this, causing thousands if not millions of repos to break?
It should be opt-in. If the reason for importing it as dt was prevailing, then the datetime library should rename as dt.
ntBre commentedon Oct 16, 2026
The rationale is given here in the issue, and this change was made in a breaking Ruff release. If you want to revert to the old behavior, you can configure
aliasesorextend-aliases, as also described above.xhan80 commentedon Oct 16, 2026
Thanks for the response. I do feel the cost / benefit tradeoff here is questionable. I'd like to ask you to reconsider and revert the datetime default.
The "import datetime as dt" was a new convention, not as established as numpy or pandas. The cPython change was only for the examples in their docs, not a style ruling, not a PEP 8 requirement. Even that was contested, for concerns about churns. The PR author also noted: "You can still import datetime if you prefer."
I don't think an examples-only docs edit should be treated as an endorsement by the wider Python community.
Almost every ICN user with "import datetime" now has to change either code or config.
We enabled ICN for its well-established flake8 conventions, not expecting newer, debatable ones to be added to the defaults.
Reverting now breaks no one.
tjkuson commentedon Oct 16, 2026
Speaking as a user of Ruff, I like the new default. It means I no longer have to add the alias myself. I think the alias makes reading and writing Python code a more pleasant experience, especially for those unfamiliar with the nuances of the datetime library. I'd be favour of including the alias by default even if the CPython docs didn't bless it (it seems sufficiently popular to me regardless).
If we're being comparative,
import datetime as dtis probably the alias with the strongest motivation of all the default set. I've always foundimport numpy as npa pretty funny convention, it only saves three characters per name!I also don't share your interpretation of the discussion under the CPython pull request. Regardless, CPython and the official documentation has very different priorities and motivations to that of a third-party linter.
Jackenmen commentedon Oct 17, 2026
Can't say that I've seen this convention before it got added as an alias to Ruff but have seen people use
dtas a name for the variable storing adatetime.datetimeobject which this is incompatible with.More broadly, I don't know how I feel about such a simple change to docs.python.org now making it possible to appeal to authority when arguing for this new linter default.
ashrub-holvi commentedon Oct 20, 2026
Not sure why people complaining -
datetime.datetimewas always confusing and annoying (compare withfrom pathlib import Path). So, definitely good thing and LLMs can help to fix existing code with minimal effort.kohlerjl commentedon Oct 20, 2026
The fact is this is not currently a widely used 'convention', even if it might have some advantages.
Unlike other common aliases, such as
nporpd,dtis a much more common abbreviation which is often used in existing code in ways that cannot be simply changed. For instance, if it is used as a kwarg in a well established apifunc(..., *, dt: float): ..., this collides withimport datetime as dtand cannot be changed without breaking downstream code.We can debate the merits of adopting a new convention, but there is no point in being dismissive for the disruption that a new rule like this causes.
ashrub-holvi commentedon Oct 21, 2026
if it's a public API then yes, but if it's something internal I am sure any modern LLM will fix it cheaply enough.
chore(deps): update ruff