Skip to content

[airflow] Skip attribute check in try catch block (AIR301)#17790

Merged
ntBre merged 1 commit intoastral-sh:mainfrom
astronomer:try-catch-airflow-rules
May 5, 2025
Merged

[airflow] Skip attribute check in try catch block (AIR301)#17790
ntBre merged 1 commit intoastral-sh:mainfrom
astronomer:try-catch-airflow-rules

Conversation

@Lee-W
Copy link
Contributor

@Lee-W Lee-W commented May 2, 2025

Summary

Skip attribute check in try catch block (AIR301)

Test Plan

update crates/ruff_linter/resources/test/fixtures/airflow/AIR301_names_try.py

@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser requested a review from ntBre May 3, 2025 14:20
@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features labels May 3, 2025
@Lee-W Lee-W force-pushed the try-catch-airflow-rules branch from c3bb041 to aca897d Compare May 5, 2025 09:32
/// member is being accessed from the non-deprecated location?
fn try_block_contains_undeprecated_attribute(
try_node: &StmtTry,
replacement: &Replacement,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I want to apply it to ProviderReplacement and other types, is there a smarter way to do so?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean pass ProviderReplacement to this function instead of Replacement? In that case, I see two options:

  • Make the function generic and introduce some kind of Replacement trait:
    fn try_block_contains_undeprecated_attribute<T: Replacement>(
         try_node: &StmtTry,
         replacement: &T,
         semantic: &SemanticModel,
    ) -> bool { /* ... */ }
    
    trait Replacement {
        fn module(&self) -> &str;
        fn name(&self) -> &str;
     }
  • Pass module and name directly to the function:
    fn try_block_contains_undeprecated_attribute(
         try_node: &StmtTry,
         module: &str,
         name: &str,
         semantic: &SemanticModel,
    ) -> bool { /* ... */ }

These both assume that you just need module and name from the Replacement types, but that seems to be the case. I think the second option is a bit easier if there are only a few fields. A trait is probably overkill.

@Lee-W Lee-W force-pushed the try-catch-airflow-rules branch from aca897d to dceaf92 Compare May 5, 2025 11:24
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me! Is this good to merge, or do you want to resolve your question about ProviderReplacement first?

/// member is being accessed from the non-deprecated location?
fn try_block_contains_undeprecated_attribute(
try_node: &StmtTry,
replacement: &Replacement,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean pass ProviderReplacement to this function instead of Replacement? In that case, I see two options:

  • Make the function generic and introduce some kind of Replacement trait:
    fn try_block_contains_undeprecated_attribute<T: Replacement>(
         try_node: &StmtTry,
         replacement: &T,
         semantic: &SemanticModel,
    ) -> bool { /* ... */ }
    
    trait Replacement {
        fn module(&self) -> &str;
        fn name(&self) -> &str;
     }
  • Pass module and name directly to the function:
    fn try_block_contains_undeprecated_attribute(
         try_node: &StmtTry,
         module: &str,
         name: &str,
         semantic: &SemanticModel,
    ) -> bool { /* ... */ }

These both assume that you just need module and name from the Replacement types, but that seems to be the case. I think the second option is a bit easier if there are only a few fields. A trait is probably overkill.

@Lee-W
Copy link
Contributor Author

Lee-W commented May 5, 2025

Thanks, this looks good to me! Is this good to merge, or do you want to resolve your question about ProviderReplacement first?

Would be nice if we could merge it first and I'll spend some time figure that out tomorrow 🙂 Thanks for the suggestions!

@ntBre ntBre merged commit 6e9fb9a into astral-sh:main May 5, 2025
34 checks passed
AlexWaygood pushed a commit that referenced this pull request May 5, 2025
<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

Skip attribute check in try catch block (`AIR301`)

## Test Plan

<!-- How was it tested? -->
update
`crates/ruff_linter/resources/test/fixtures/airflow/AIR301_names_try.py`
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request May 6, 2025
…l-sh#17790)

<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

Skip attribute check in try catch block (`AIR301`)

## Test Plan

<!-- How was it tested? -->
update
`crates/ruff_linter/resources/test/fixtures/airflow/AIR301_names_try.py`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants