Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flake8-naming]: Respect import conventions (N817) #12922

Merged
merged 2 commits into from
Aug 16, 2024

Conversation

MichaReiser
Copy link
Member

Summary

Fixes #12916 by respecting the configured import conventions in N817.

I decided to respect the conventions regardless on whether ICN001 is enabled or not because it makes the change easier to explain (fewer conditions when the behavior applies)
and seems like a reasonable default.

Test Plan

Added tests

Breaking change

One could argue that this is a breaking change because ET imports flagged before will now no-longer be flagged, requiring users to adopt their configuration if they want to keep flagging ET.
I think it's fine but interested in more opinions.

@MichaReiser MichaReiser added the incompatibility Incompatibility between different Ruff tools or rules (formatter, isort, linter) label Aug 16, 2024
| ^^^^^^^^^^^^^^^ N817
|

N817.py:6:8: N817 CamelCase `ElementTree` imported as acronym `ET`
Copy link
Member Author

Choose a reason for hiding this comment

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

The configuration for this test run specifies that the convention for importing ElementTree is XET. That's why ET gets flagged.

Copy link
Member

Choose a reason for hiding this comment

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

And the pre-existing test ensures that import ElementTree as ET is not flagged with the default settings, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

@MichaReiser MichaReiser force-pushed the fix-icn001-n817-incompatibility branch from 600c1f2 to 173cc67 Compare August 16, 2024 10:09
Copy link
Contributor

github-actions bot commented Aug 16, 2024

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+0 -2 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)

apache/airflow (+0 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --no-preview --select ALL

- scripts/ci/testing/summarize_junit_failures.py:23:8: N817 CamelCase `ElementTree` imported as acronym `ET`
- scripts/in_container/check_junitxml_result.py:21:8: N817 CamelCase `ElementTree` imported as acronym `ET`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
N817 2 0 2 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -2 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)

apache/airflow (+0 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

- scripts/ci/testing/summarize_junit_failures.py:23:8: N817 CamelCase `ElementTree` imported as acronym `ET`
- scripts/in_container/check_junitxml_result.py:21:8: N817 CamelCase `ElementTree` imported as acronym `ET`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
N817 2 0 2 0 0

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM. I think this is what users would intuitively expect and is a reduction in scope, so I don't see it as particularly breaking

Comment on lines +26 to +28
/// [`lint.flake8-boolean-trap.extend-allowed-calls`] option are allowed.
///
///
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// [`lint.flake8-boolean-trap.extend-allowed-calls`] option are allowed.
///
///
/// [`lint.flake8-import-conventions.banned-aliases`] option are allowed.
///

Also, I notice you used square brackets but didn't add a link at the end. Was that deliberate -- do we have a mechanism that adds links automatically to settings?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we have some fancy script that resolves settings (and validates them)

image

Copy link
Member

Choose a reason for hiding this comment

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

Fancy script or no fancy script, you're still referring to the wrong setting here: the lint.flake8-boolean-trap.extend-allowed-calls setting has nothing to do with this rule

Copy link
Member

Choose a reason for hiding this comment

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

I filed #12935 to address this

| ^^^^^^^^^^^^^^^ N817
|

N817.py:6:8: N817 CamelCase `ElementTree` imported as acronym `ET`
Copy link
Member

Choose a reason for hiding this comment

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

And the pre-existing test ensures that import ElementTree as ET is not flagged with the default settings, correct?

@MichaReiser MichaReiser changed the title [flake8-naming]: Respect import conventions (N8171) [flake8-naming]: Respect import conventions (N817) Aug 16, 2024
@MichaReiser MichaReiser enabled auto-merge (squash) August 16, 2024 15:24
@MichaReiser MichaReiser merged commit aba0d83 into main Aug 16, 2024
16 checks passed
@MichaReiser MichaReiser deleted the fix-icn001-n817-incompatibility branch August 16, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incompatibility Incompatibility between different Ruff tools or rules (formatter, isort, linter)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICN001 and N817 don't play with each other
2 participants