Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b9e1c75ab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Thank you. Please take a look at our AI Policy (https://github.com/astral-sh/ruff/blob/main/CONTRIBUTING.md#use-of-ai). Your summary gives me a strong impression that it was written by AI |
thanks for pointing this out. i read the AI policy. i used AI tooling to help open the PR and draft the first description, but i reviewed the diff and tested it locally on Windows. and i want to know weather the review comment by the [chatgpt-codex-connector] that i should handle it? |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dda755d551
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b75a2639e0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Thanks for looking into this and coming up with a fix! However, the new code looks quite complicated, and I didn't realize that TID255 already bails out without a fix if multiple imports are affected: What do you think about doing the same here? I think a minimal patch like this would share the same helper here and take care of the issue: diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/lazy_import_immediately_resolved.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/lazy_import_immediately_resolved.rs
index 2cb5fee1e4..9eab43f6b3 100644
--- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/lazy_import_immediately_resolved.rs
+++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/lazy_import_immediately_resolved.rs
@@ -126,8 +126,8 @@ fn lazy_import_statement<'a>(binding: &Binding, semantic: &SemanticModel<'a>) ->
.then_some(stmt)
}
-/// Return `true` if removing `lazy` only makes the resolved import eager.
-fn is_single_member_import(stmt: &Stmt) -> bool {
+/// Return `true` if changing `lazy` affects only one imported name.
+pub(super) fn is_single_member_import(stmt: &Stmt) -> bool {
match stmt {
Stmt::Import(StmtImport { names, .. }) | Stmt::ImportFrom(StmtImportFrom { names, .. }) => {
names.len() == 1
diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/lazy_import_mismatch.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/lazy_import_mismatch.rs
index 1aae71b8de..09b49a8c8c 100644
--- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/lazy_import_mismatch.rs
+++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/lazy_import_mismatch.rs
@@ -2,6 +2,7 @@ use ruff_macros::{ViolationMetadata, derive_message_formats};
use ruff_python_ast::{PythonVersion, Stmt, StmtImport, StmtImportFrom};
use ruff_text_size::{Ranged, TextRange, TextSize};
+use super::lazy_import_immediately_resolved::is_single_member_import;
use crate::checkers::ast::Checker;
use crate::codes::Category;
use crate::rules::flake8_tidy_imports::rules::BannedModuleImportPolicies;
@@ -50,7 +51,7 @@ enum LazyImportPolicy {
}
impl Violation for LazyImportMismatch {
- const FIX_AVAILABILITY: FixAvailability = FixAvailability::Always;
+ const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;
#[derive_message_formats]
fn message(&self) -> String {
@@ -168,6 +169,10 @@ fn report_lazy_import_policy(
policy: LazyImportPolicy,
) {
let mut diagnostic = checker.report_diagnostic(LazyImportMismatch { policy, name }, range);
+ // Changing the entire statement could violate another imported name's policy.
+ if !is_single_member_import(stmt) {
+ return;
+ }
match policy {
LazyImportPolicy::RequireLazy => {
diagnostic.set_fix(Fix::unsafe_edit(Edit::insertion( |
Share TID255's single-member guard so conflicting import policies still produce diagnostics without oscillating fixes. Cover both import forms, both fix directions, and the single-member fixes in regression tests. Merge upstream main to resolve the PR conflict.
|
好,我看了一下这个 PR,我之前弄的确实有点复杂了。我觉得你提出的方向是可以的,我按照这个方向修改了一个版本,提交了 commit 修改。(因为我不是英语母语使用者,这个用了 AI 进行翻译我的中文。) English translation (AI-assisted):
|
ntBre
left a comment
There was a problem hiding this comment.
Thank you! I made a small tweak to the docs and then switched the tests over to our new mdtest framework, but this looks great.
flake8-tidy-imports] Skip fixes for multi-member imports (TID254)
|
This fixes #26450.
TID254 now reports policy violations without offering a fix when an import statement contains multiple names. Single-name imports remain fixable. This prevents conflicting lazy-import requirements from repeatedly adding and removing
lazy, and uses the same single-member check as TID255.The tests cover both
importandfrom ... import ..., including conflicting policies and fixes in both directions.btw: cuz i not the natvie English speaker, i will use ai to imporve my txt, which may let it look like a AI generate....