Skip to content

Fix ICN001 (unconventional-import-alias) violations in ruff v0.17.0 - #4946

Merged
seisman merged 1 commit into
mainfrom
ruff/0.17.0
Oct 10, 2026
Merged

seisman merged 1 commit into
mainfrom
ruff/0.17.0

Conversation

@seisman

@seisman seisman commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

ruff v0.17.0 introduces a breaking change to the rule ICN001 (unconventional-import-alias), resulting failures in the Style Checks workflow (https://github.com/GenericMappingTools/pygmt/actions/runs/38022301186/job/114125705838)
with errors like:

unconventional-import-alias: `datetime` should be imported as `dt`
 --> doc/conf.py:7:8
  |
5 | """
6 |
7 | import datetime
  |        ^^^^^^^^
8 | import re
  |
help: Alias `datetime` to `dt`
   |
6  |
   - import datetime
7  + import datetime as dt
8  | import re
--------------------------------------------------------------------------------
30 | author = "The PyGMT Developers"
   - copyright = f"2017-{datetime.date.today().year}, {author}"  # ruff: ignore[builtin-variable-shadowing]
31 + copyright = f"2017-{dt.date.today().year}, {author}"  # ruff: ignore[builtin-variable-shadowing]
32 | version = "dev" if isdev else __version__
   |
note: This is an unsafe fix and may change runtime behavior

ruff v0.17.0 recommends import datetime as dt, rather than import datetime, following the Python official documentation at https://docs.python.org/3.13/library/datetime.html#datetime.timedelta.

This PR fixes the violations. The changes are automatically done by running ruff check --fix --unsafe-fixes.

The new codes still works with old ruff versions, so no ruff version bump here.

@seisman seisman added this to the 0.20.0 milestone Oct 10, 2026
@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog final review call This PR requires final review and approval from a second reviewer labels Oct 10, 2026

@yvonnefroehlich yvonnefroehlich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK with following the rule.

But I believe this can cause confusion by overwriting it accidentally when using dt as a variable name for a time difference.

@seisman
seisman merged commit ffb78cf into main Oct 10, 2026
25 of 28 checks passed
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Oct 10, 2026
@seisman
seisman deleted the ruff/0.17.0 branch October 10, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants