Skip to content

add autofix for PIE804#7884

Merged
charliermarsh merged 3 commits intoastral-sh:mainfrom
diceroll123:PIE804-autofix
Oct 11, 2023
Merged

add autofix for PIE804#7884
charliermarsh merged 3 commits intoastral-sh:mainfrom
diceroll123:PIE804-autofix

Conversation

@diceroll123
Copy link
Contributor

@diceroll123 diceroll123 commented Oct 10, 2023

Summary

Adds autofix for PIE804, closes #6783.

I've split the ifs apart to make the diagnostics easier to read. Open to suggestions if that's not desired!

Test Plan

cargo test, and manually.

@diceroll123 diceroll123 changed the title add autofix for PIE804 add autofix for PIE804 Oct 10, 2023
Comment on lines +87 to +92
key.as_constant_expr()
.unwrap()
.value
.as_str()
.unwrap()
.value,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not particularly proud of this, is there a less scary-looking way to do this?

@github-actions
Copy link
Contributor

github-actions bot commented Oct 10, 2023

PR Check Results

Ecosystem

ℹ️ ecosystem check detected changes. (+24, -24, 0 error(s))

airflow (+24, -24)

- [*] 16008 fixable with the `--fix` option (6314 hidden fixes can be enabled with the `--unsafe-fixes` option).
+ [*] 16031 fixable with the `--fix` option (6314 hidden fixes can be enabled with the `--unsafe-fixes` option).
- tests/providers/amazon/aws/operators/test_eks.py:728:30: PIE804 Unnecessary `dict` kwargs
+ tests/providers/amazon/aws/operators/test_eks.py:728:30: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/amazon/aws/utils/test_waiter_with_logging.py:102:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/amazon/aws/utils/test_waiter_with_logging.py:102:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/amazon/aws/utils/test_waiter_with_logging.py:132:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/amazon/aws/utils/test_waiter_with_logging.py:132:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/amazon/aws/utils/test_waiter_with_logging.py:181:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/amazon/aws/utils/test_waiter_with_logging.py:181:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/amazon/aws/utils/test_waiter_with_logging.py:219:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/amazon/aws/utils/test_waiter_with_logging.py:219:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/amazon/aws/utils/test_waiter_with_logging.py:268:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/amazon/aws/utils/test_waiter_with_logging.py:268:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/amazon/aws/utils/test_waiter_with_logging.py:61:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/amazon/aws/utils/test_waiter_with_logging.py:61:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/cncf/kubernetes/utils/test_pod_manager.py:803:30: PIE804 Unnecessary `dict` kwargs
+ tests/providers/cncf/kubernetes/utils/test_pod_manager.py:803:30: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/google/cloud/hooks/test_life_sciences.py:125:24: PIE804 Unnecessary `dict` kwargs
+ tests/providers/google/cloud/hooks/test_life_sciences.py:125:24: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/google/cloud/hooks/test_life_sciences.py:154:24: PIE804 Unnecessary `dict` kwargs
+ tests/providers/google/cloud/hooks/test_life_sciences.py:154:24: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/google/cloud/hooks/test_life_sciences.py:231:24: PIE804 Unnecessary `dict` kwargs
+ tests/providers/google/cloud/hooks/test_life_sciences.py:231:24: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/google/cloud/hooks/test_life_sciences.py:259:24: PIE804 Unnecessary `dict` kwargs
+ tests/providers/google/cloud/hooks/test_life_sciences.py:259:24: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/google/cloud/operators/test_kubernetes_engine.py:404:30: PIE804 Unnecessary `dict` kwargs
+ tests/providers/google/cloud/operators/test_kubernetes_engine.py:404:30: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/google/firebase/hooks/test_firestore.py:100:24: PIE804 Unnecessary `dict` kwargs
+ tests/providers/google/firebase/hooks/test_firestore.py:100:24: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/google/firebase/hooks/test_firestore.py:122:24: PIE804 Unnecessary `dict` kwargs
+ tests/providers/google/firebase/hooks/test_firestore.py:122:24: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/google/firebase/hooks/test_firestore.py:189:24: PIE804 Unnecessary `dict` kwargs
+ tests/providers/google/firebase/hooks/test_firestore.py:189:24: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/google/firebase/hooks/test_firestore.py:216:24: PIE804 Unnecessary `dict` kwargs
+ tests/providers/google/firebase/hooks/test_firestore.py:216:24: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/telegram/hooks/test_telegram.py:106:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/telegram/hooks/test_telegram.py:106:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/telegram/hooks/test_telegram.py:125:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/telegram/hooks/test_telegram.py:125:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/telegram/hooks/test_telegram.py:144:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/telegram/hooks/test_telegram.py:144:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/telegram/hooks/test_telegram.py:171:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/telegram/hooks/test_telegram.py:171:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/providers/telegram/hooks/test_telegram.py:191:9: PIE804 Unnecessary `dict` kwargs
+ tests/providers/telegram/hooks/test_telegram.py:191:9: PIE804 [*] Unnecessary `dict` kwargs
- tests/utils/test_compression.py:76:13: PIE804 Unnecessary `dict` kwargs
+ tests/utils/test_compression.py:76:13: PIE804 [*] Unnecessary `dict` kwargs

Rules changed: 1
Rule Changes Additions Removals
PIE804 46 23 23

@charliermarsh charliermarsh force-pushed the PIE804-autofix branch 2 times, most recently from a36b277 to 8d6dd2c Compare October 11, 2023 00:58
let kwargs = keys
.iter()
.filter_map(|key| key.as_ref().and_then(as_kwarg))
.collect::<Vec<_>>();
Copy link
Member

Choose a reason for hiding this comment

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

I restructured it such that, when we validate the keyword arguments, we also return the valid keyword argument name. That lets us avoid a bunch of unwraps below. In other words: when we validate, we return the validated data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooo. Love it! Thanks!

@charliermarsh charliermarsh added the fixes Related to suggested fixes for violations label Oct 11, 2023
@charliermarsh charliermarsh enabled auto-merge (squash) October 11, 2023 00:59
@charliermarsh charliermarsh merged commit 826868d into astral-sh:main Oct 11, 2023
konstin pushed a commit that referenced this pull request Oct 11, 2023
charliermarsh pushed a commit that referenced this pull request Oct 11, 2023
## Summary

`foo(**{})` was an overlooked edge case for `PIE804` which introduced a
crash within the Fix, introduced in #7884.

I've made it so that `foo(**{})` turns into `foo()` when applied with
`--fix`, but is that desired/expected? 🤔 Should we just ignore instead?

## Test Plan

`cargo test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Requested enhancement] PIE804 autofix

2 participants