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
ICN001 import-alias-is-not-conventional should check "from" imports #2070
ICN001 import-alias-is-not-conventional should check "from" imports #2070
Conversation
This might be a naive implementation, since I copied and pasted the code block from the `Stmt::Import` section.
Next step, actually add real tests.
Thanks! I'll review this in a bit. |
Couple of things. I know my commit history is pretty messy. I'm assuming that's something you can just discard during the PR process? Also, I modified |
|
|
||
import xml.dom.minidom as md | ||
from xml.dom import minidom as md | ||
from xml.dom.minidom import parseString as pstr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a test for an import from
with multiple members, only one of which needs to be flagged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding test cases was a good call.
Currently, it considers this a violation:
import xml.dom.minidom
But it doesn't catch these:
from xml.dom import minidom
from xml.dom.minidom import parseString
I'll try to track down what's up. I think these examples should all be violations.
Keeps the string from being created unless it's needed.
Oops, looked like you merged the PR while I was still trying to add some more test conditions. Would you like me to just create a separate PR for that? Or work on it here? |
Gah sorry, yeah, I jumped the gun. Let’s do it in a separate PR please. |
No big deal. I think everything still works fine in main, there is just the slight inconsistency between the |
@@ -1231,6 +1231,28 @@ where | |||
} | |||
|
|||
if let Some(asname) = &alias.node.asname { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you haven't caught it: this block only runs when the as
is set (e.g. from foo import bar as baz
, but not from foo import bar
). I think you can lift all these changes out of this if
, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhhhhhh, yeah, I see it now. I put it under that condition because I thought the original call was under the same clause on line 896, but I miss-read it. It's not under the if let Some(asname) = &alias.node.asname
so mine shouldn't be either. Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Just for clarity in communication: do you plan to fix this, or want me to?)
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) | `^0.0.229` -> `^0.0.230` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.230/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.230/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.230/compatibility-slim/0.0.229)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.230/confidence-slim/0.0.229)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.230`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.230) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.229...v0.0.230) #### What's Changed - fix: pin rustpython to the same revision to fix cargo vendor by [@​figsoda](https://togithub.com/figsoda) in [astral-sh/ruff#2069 - feat: implementation for TRY004 by [@​sbrugman](https://togithub.com/sbrugman) in [astral-sh/ruff#2066 - ICN001 import-alias-is-not-conventional should check "from" imports by [@​Zeddicus414](https://togithub.com/Zeddicus414) in [astral-sh/ruff#2070 - Update link to Pylint parity tracking issue by [@​cosmojg](https://togithub.com/cosmojg) in [astral-sh/ruff#2074 - ICN001 check from imports that have no alias by [@​Zeddicus414](https://togithub.com/Zeddicus414) in [astral-sh/ruff#2072 - Index source code upfront to power (row, column) lookups by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#1990 - Remove remaining `ropey` usages by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#2076 - Include package path in cache key by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#2077 - feat: update scripts to new rules structure by [@​sbrugman](https://togithub.com/sbrugman) in [astral-sh/ruff#2078 - Base `INP` check on package inference by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#2079 - Improve generator precedence operations by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#2080 - Support decorators in source code generator by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#2081 - feat: enable autofix for TRY004 by [@​sbrugman](https://togithub.com/sbrugman) in [astral-sh/ruff#2084 - Refactor, decouple and support "PL" by [@​not-my-profile](https://togithub.com/not-my-profile) in [astral-sh/ruff#2051 - \[`pep8-naming`]\[`N806`] Don't mark `TypeVar` & `NewType` Assignment as Errors by [@​saadmk11](https://togithub.com/saadmk11) in [astral-sh/ruff#2085 - Update linters pypi links to latest version by [@​alonme](https://togithub.com/alonme) in [astral-sh/ruff#2062 - flake8\_to_ruff: support `isort` options by [@​shannonrothe](https://togithub.com/shannonrothe) in [astral-sh/ruff#2082 - Update RustPython to fix `Dict.keys` type by [@​harupy](https://togithub.com/harupy) in [astral-sh/ruff#2086 #### New Contributors - [@​figsoda](https://togithub.com/figsoda) made their first contribution in [astral-sh/ruff#2069 - [@​cosmojg](https://togithub.com/cosmojg) made their first contribution in [astral-sh/ruff#2074 - [@​alonme](https://togithub.com/alonme) made their first contribution in [astral-sh/ruff#2062 - [@​shannonrothe](https://togithub.com/shannonrothe) made their first contribution in [astral-sh/ruff#2082 **Full Changelog**: astral-sh/ruff@v0.0.229...v0.0.230 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/ixm-one/pytest-cmake-presets). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMDguNCIsInVwZGF0ZWRJblZlciI6IjM0LjEwOC40In0=--> Signed-off-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
See #2047