-
Notifications
You must be signed in to change notification settings - Fork 926
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
Respect insertion location when importing symbols #4258
Conversation
@@ -18,10 +17,7 @@ pub struct Importer<'a> { | |||
python_ast: &'a Suite, | |||
locator: &'a Locator<'a>, | |||
stylist: &'a Stylist<'a>, | |||
/// A map from module name to top-level `StmtKind::ImportFrom` statements. | |||
import_from_map: FxHashMap<&'a str, &'a Stmt>, |
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.
I opted to get rid of this and just do a full search. The number of imports is typically not huge, this operation is relatively rare, and we'd now have to track FxHashMap<&'a str, Vec<&'a Stmt>>
anyway.
crates/ruff/src/importer.rs
Outdated
pub fn find_import_from(&self, module: &str, at: TextSize) -> Option<&Stmt> { | ||
let idx = self | ||
.ordered_imports | ||
.partition_point(|stmt| stmt.start() < at); |
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.
Hard to reason about whether this preliminary search is worth it.
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.
Probably not?
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.
If we assume that in most file all imports are at the start of the file, just if stmt.start() > at { return false; }
in the find should be faster.
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinux
Windows
|
diagnostic.set_fix(Importer::new(python_ast, locator, stylist).add_import(required_import)); | ||
diagnostic.set_fix( | ||
Importer::new(python_ast, locator, stylist) | ||
.add_import(required_import, TextSize::default()), |
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.
Shouldn't this use the location of the first non-import statement, or do they need to be inserted even before the other imports?
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.
They should be inserted at the top of the file -- since it has to work with __future__
imports.
ee716d3
to
0b6e20c
Compare
[![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) ([changelog](https://togithub.com/charliermarsh/ruff/releases)) | `^0.0.265` -> `^0.0.267` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/compatibility-slim/0.0.265)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/confidence-slim/0.0.265)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.267`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.267) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.266...v0.0.267) <!-- Release notes generated using configuration in .github/release.yml at main --> #### Summary Follow-up release to v0.0.266 to fix an issue with `python -m ruff`- and `import ruff`-based workflows. (No new rules or functionality.) #### What's Changed ##### Rules - Implement `RUF010` to detect explicit type conversions within f-strings by [@​LotemAm](https://togithub.com/LotemAm) in [astral-sh/ruff#4387 ##### Other Changes - Workaround for maturin bug by [@​konstin](https://togithub.com/konstin) in [astral-sh/ruff#4399 #### New Contributors - [@​OMEGARAZER](https://togithub.com/OMEGARAZER) made their first contribution in [astral-sh/ruff#3938 - [@​LotemAm](https://togithub.com/LotemAm) made their first contribution in [astral-sh/ruff#4387 **Full Changelog**: astral-sh/ruff@v0.0.266...v0.0.267 ### [`v0.0.266`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.266) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.265...v0.0.266) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Breaking Changes - Remove deprecated `update-check` setting by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4313 - JSON Emitter: Use one indexed column numbers for edits by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4007 ##### Rules - \[`pygrep-hooks`] Implement pygrep-hook's Mock-mistake diagnostic by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4366 - \[`pylint`] Implement `nested-min-max` (`W3301`) by [@​mccullocht](https://togithub.com/mccullocht) in [astral-sh/ruff#4200 - \[`flynt`] Implement Flynt static string join transform as FLY002 by [@​akx](https://togithub.com/akx) in [astral-sh/ruff#4196 - \[`pylint`] Include positional- and keyword-only arguments in too-many-arguments by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4329 - \[`ruff`] Update confusable character mapping by [@​akx](https://togithub.com/akx) in [astral-sh/ruff#4274 ##### Settings - Add .git-rewrite folder to default ignored folder paths by [@​jleclanche](https://togithub.com/jleclanche) in [astral-sh/ruff#4261 - Feat: detect changes also in configuration files by [@​mikeleppane](https://togithub.com/mikeleppane) in [astral-sh/ruff#4169 ##### Bug Fixes - Revert the B027 autofix logic by [@​aacunningham](https://togithub.com/aacunningham) in [astral-sh/ruff#4310 - Consider Flask app logger as logger candidate by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4253 - Enforce max-doc-length for multi-line docstrings by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4347 - Avoid re-using imports beyond current edit site by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4378 - Respect insertion location when importing symbols by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4258 - Fix jemalloc page size on aarch64 by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4247 - Fix replace_whitespace() tabulation to space by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [astral-sh/ruff#4226 - Avoid fixing `PD002` in a lambda expression by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4286 - Avoid `D403` if first char cannot be uppercased by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4283 - Avoid panics for f-string rewrites at start-of-file by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4291 - Rewrite `not not a` as `bool(a)` in boolean contexts by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4294 - Include static and class methods in in abstract decorator list by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4298 - Specify exact command in incorrect parentheses suggestion by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4300 - Ignore `TRY301` exceptions without except handlers by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4301 - Preserve whitespace around `ListComp` brackets in `C419` by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4099 - Tweak capitalization of B021 message by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4350 - Avoid debug panic with empty indent replacement by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4364 - Use target name in hardcoded-password diagnostics by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4365 - Avoid underflow in expected-special-method-signature by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4377 - Respect `__all__` imports when determining definition visibility by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4357 - Ignore some methods on list in `flake8-boolean-trap` by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4385 - Fix false positives in PD002 by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [astral-sh/ruff#4337 - Run autofix on initial watcher pass by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4311 - Avoid SIM105 autofixes that would remove comments by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4330 - Handle `.encode` calls on parenthesized expressions by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4338 - Truncate `SyntaxError`s before newline character by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4124 - Use non-empty ranges for logical-lines diagnostics by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4133 #### New Contributors - [@​jleclanche](https://togithub.com/jleclanche) made their first contribution in [astral-sh/ruff#4261 - [@​aureliojargas](https://togithub.com/aureliojargas) made their first contribution in [astral-sh/ruff#4306 - [@​intgr](https://togithub.com/intgr) made their first contribution in [astral-sh/ruff#4304 - [@​mikeleppane](https://togithub.com/mikeleppane) made their first contribution in [astral-sh/ruff#4169 - [@​dependabot](https://togithub.com/dependabot) made their first contribution in [astral-sh/ruff#4354 **Full Changelog**: astral-sh/ruff@v0.0.265...v0.0.266 </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:eyJjcmVhdGVkSW5WZXIiOiIzNS43OS4xIiwidXBkYXRlZEluVmVyIjoiMzUuNzkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Signed-off-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![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) ([changelog](https://togithub.com/charliermarsh/ruff/releases)) | `==0.0.265` -> `==0.0.267` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/compatibility-slim/0.0.265)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/confidence-slim/0.0.265)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.267`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.267) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.266...v0.0.267) <!-- Release notes generated using configuration in .github/release.yml at main --> #### Summary Follow-up release to v0.0.266 to fix an issue with `python -m ruff`- and `import ruff`-based workflows. (No new rules or functionality.) #### What's Changed ##### Rules - Implement `RUF010` to detect explicit type conversions within f-strings by [@​LotemAm](https://togithub.com/LotemAm) in [astral-sh/ruff#4387 ##### Other Changes - Workaround for maturin bug by [@​konstin](https://togithub.com/konstin) in [astral-sh/ruff#4399 #### New Contributors - [@​OMEGARAZER](https://togithub.com/OMEGARAZER) made their first contribution in [astral-sh/ruff#3938 - [@​LotemAm](https://togithub.com/LotemAm) made their first contribution in [astral-sh/ruff#4387 **Full Changelog**: astral-sh/ruff@v0.0.266...v0.0.267 ### [`v0.0.266`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.266) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.265...v0.0.266) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Breaking Changes - Remove deprecated `update-check` setting by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4313 - JSON Emitter: Use one indexed column numbers for edits by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4007 ##### Rules - \[`pygrep-hooks`] Implement pygrep-hook's Mock-mistake diagnostic by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4366 - \[`pylint`] Implement `nested-min-max` (`W3301`) by [@​mccullocht](https://togithub.com/mccullocht) in [astral-sh/ruff#4200 - \[`flynt`] Implement Flynt static string join transform as FLY002 by [@​akx](https://togithub.com/akx) in [astral-sh/ruff#4196 - \[`pylint`] Include positional- and keyword-only arguments in too-many-arguments by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4329 - \[`ruff`] Update confusable character mapping by [@​akx](https://togithub.com/akx) in [astral-sh/ruff#4274 ##### Settings - Add .git-rewrite folder to default ignored folder paths by [@​jleclanche](https://togithub.com/jleclanche) in [astral-sh/ruff#4261 - Feat: detect changes also in configuration files by [@​mikeleppane](https://togithub.com/mikeleppane) in [astral-sh/ruff#4169 ##### Bug Fixes - Revert the B027 autofix logic by [@​aacunningham](https://togithub.com/aacunningham) in [astral-sh/ruff#4310 - Consider Flask app logger as logger candidate by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4253 - Enforce max-doc-length for multi-line docstrings by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4347 - Avoid re-using imports beyond current edit site by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4378 - Respect insertion location when importing symbols by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4258 - Fix jemalloc page size on aarch64 by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4247 - Fix replace_whitespace() tabulation to space by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [astral-sh/ruff#4226 - Avoid fixing `PD002` in a lambda expression by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4286 - Avoid `D403` if first char cannot be uppercased by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4283 - Avoid panics for f-string rewrites at start-of-file by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4291 - Rewrite `not not a` as `bool(a)` in boolean contexts by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4294 - Include static and class methods in in abstract decorator list by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4298 - Specify exact command in incorrect parentheses suggestion by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4300 - Ignore `TRY301` exceptions without except handlers by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4301 - Preserve whitespace around `ListComp` brackets in `C419` by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4099 - Tweak capitalization of B021 message by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4350 - Avoid debug panic with empty indent replacement by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4364 - Use target name in hardcoded-password diagnostics by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4365 - Avoid underflow in expected-special-method-signature by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4377 - Respect `__all__` imports when determining definition visibility by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4357 - Ignore some methods on list in `flake8-boolean-trap` by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4385 - Fix false positives in PD002 by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [astral-sh/ruff#4337 - Run autofix on initial watcher pass by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4311 - Avoid SIM105 autofixes that would remove comments by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4330 - Handle `.encode` calls on parenthesized expressions by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4338 - Truncate `SyntaxError`s before newline character by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4124 - Use non-empty ranges for logical-lines diagnostics by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4133 #### New Contributors - [@​jleclanche](https://togithub.com/jleclanche) made their first contribution in [astral-sh/ruff#4261 - [@​aureliojargas](https://togithub.com/aureliojargas) made their first contribution in [astral-sh/ruff#4306 - [@​intgr](https://togithub.com/intgr) made their first contribution in [astral-sh/ruff#4304 - [@​mikeleppane](https://togithub.com/mikeleppane) made their first contribution in [astral-sh/ruff#4169 - [@​dependabot](https://togithub.com/dependabot) made their first contribution in [astral-sh/ruff#4354 **Full Changelog**: astral-sh/ruff@v0.0.265...v0.0.266 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, 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/allenporter/flux-local). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS43OS4xIiwidXBkYXRlZEluVmVyIjoiMzUuNzkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![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) ([changelog](https://togithub.com/charliermarsh/ruff/releases)) | `==0.0.265` -> `==0.0.267` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/compatibility-slim/0.0.265)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.267/confidence-slim/0.0.265)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.267`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.267) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.266...v0.0.267) <!-- Release notes generated using configuration in .github/release.yml at main --> #### Summary Follow-up release to v0.0.266 to fix an issue with `python -m ruff`- and `import ruff`-based workflows. (No new rules or functionality.) #### What's Changed ##### Rules - Implement `RUF010` to detect explicit type conversions within f-strings by [@​LotemAm](https://togithub.com/LotemAm) in [astral-sh/ruff#4387 ##### Other Changes - Workaround for maturin bug by [@​konstin](https://togithub.com/konstin) in [astral-sh/ruff#4399 #### New Contributors - [@​OMEGARAZER](https://togithub.com/OMEGARAZER) made their first contribution in [astral-sh/ruff#3938 - [@​LotemAm](https://togithub.com/LotemAm) made their first contribution in [astral-sh/ruff#4387 **Full Changelog**: astral-sh/ruff@v0.0.266...v0.0.267 ### [`v0.0.266`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.266) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.265...v0.0.266) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Breaking Changes - Remove deprecated `update-check` setting by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4313 - JSON Emitter: Use one indexed column numbers for edits by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4007 ##### Rules - \[`pygrep-hooks`] Implement pygrep-hook's Mock-mistake diagnostic by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4366 - \[`pylint`] Implement `nested-min-max` (`W3301`) by [@​mccullocht](https://togithub.com/mccullocht) in [astral-sh/ruff#4200 - \[`flynt`] Implement Flynt static string join transform as FLY002 by [@​akx](https://togithub.com/akx) in [astral-sh/ruff#4196 - \[`pylint`] Include positional- and keyword-only arguments in too-many-arguments by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4329 - \[`ruff`] Update confusable character mapping by [@​akx](https://togithub.com/akx) in [astral-sh/ruff#4274 ##### Settings - Add .git-rewrite folder to default ignored folder paths by [@​jleclanche](https://togithub.com/jleclanche) in [astral-sh/ruff#4261 - Feat: detect changes also in configuration files by [@​mikeleppane](https://togithub.com/mikeleppane) in [astral-sh/ruff#4169 ##### Bug Fixes - Revert the B027 autofix logic by [@​aacunningham](https://togithub.com/aacunningham) in [astral-sh/ruff#4310 - Consider Flask app logger as logger candidate by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4253 - Enforce max-doc-length for multi-line docstrings by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4347 - Avoid re-using imports beyond current edit site by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4378 - Respect insertion location when importing symbols by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4258 - Fix jemalloc page size on aarch64 by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4247 - Fix replace_whitespace() tabulation to space by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [astral-sh/ruff#4226 - Avoid fixing `PD002` in a lambda expression by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4286 - Avoid `D403` if first char cannot be uppercased by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4283 - Avoid panics for f-string rewrites at start-of-file by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4291 - Rewrite `not not a` as `bool(a)` in boolean contexts by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4294 - Include static and class methods in in abstract decorator list by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4298 - Specify exact command in incorrect parentheses suggestion by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4300 - Ignore `TRY301` exceptions without except handlers by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4301 - Preserve whitespace around `ListComp` brackets in `C419` by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [astral-sh/ruff#4099 - Tweak capitalization of B021 message by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4350 - Avoid debug panic with empty indent replacement by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4364 - Use target name in hardcoded-password diagnostics by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4365 - Avoid underflow in expected-special-method-signature by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4377 - Respect `__all__` imports when determining definition visibility by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4357 - Ignore some methods on list in `flake8-boolean-trap` by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4385 - Fix false positives in PD002 by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [astral-sh/ruff#4337 - Run autofix on initial watcher pass by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4311 - Avoid SIM105 autofixes that would remove comments by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4330 - Handle `.encode` calls on parenthesized expressions by [@​charliermarsh](https://togithub.com/charliermarsh) in [astral-sh/ruff#4338 - Truncate `SyntaxError`s before newline character by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4124 - Use non-empty ranges for logical-lines diagnostics by [@​MichaReiser](https://togithub.com/MichaReiser) in [astral-sh/ruff#4133 #### New Contributors - [@​jleclanche](https://togithub.com/jleclanche) made their first contribution in [astral-sh/ruff#4261 - [@​aureliojargas](https://togithub.com/aureliojargas) made their first contribution in [astral-sh/ruff#4306 - [@​intgr](https://togithub.com/intgr) made their first contribution in [astral-sh/ruff#4304 - [@​mikeleppane](https://togithub.com/mikeleppane) made their first contribution in [astral-sh/ruff#4169 - [@​dependabot](https://togithub.com/dependabot) made their first contribution in [astral-sh/ruff#4354 **Full Changelog**: astral-sh/ruff@v0.0.265...v0.0.266 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, 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/allenporter/pyrainbird). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS43OS4xIiwidXBkYXRlZEluVmVyIjoiMzUuNzkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Summary
Previously,
Importer
would only track the most recently-seen top-level import statement, and would add any new imports after that statement. However, because we visit function bodies and other scopes in a deferred manner, then if there are top-level imports below a given function, we'll visit those imports, then visit the function body, then insert the new import after the function.This causes two problems: (1) it breaks the invariant, enforced in the fixer, that edits are ordered, since the import insertion can come after the edit that makes use of the symbol; and (2) in theory, this could lead to broken code, since a function could be called before we reach the import statement (since that statement comes later in the module).
The fix here is to track all import statements, and return the last import statement before a given edit location.
Closes #4208.