Skip to content
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

feat: update C416 with dict comprehension (autofixable) #3605

Merged
merged 7 commits into from Mar 19, 2023

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Mar 19, 2023

Update C416 with dict comprehensions which is auto-fixable.

This required changing the function signature of unnecessary_comprehension to take a vector of elements as a dict comprehension has 2 of them (key, value). Look at review comments

resolves: #3598

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2023

PR Check Results

Ecosystem

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

airflow (+7, -0)

+ airflow/api/common/experimental/get_lineage.py:50:25: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
+ airflow/models/dagrun.py:281:16: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
+ airflow/operators/python.py:386:37: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
+ airflow/www/decorators.py:103:26: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
+ docs/conf.py:410:29: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
+ docs/conf.py:411:15: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
+ docs/conf.py:413:39: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)

cibuildwheel (+1, -0)

+ test/test_dependency_versions.py:48:12: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)

zulip (+2, -0)

+ zerver/lib/onboarding.py:26:18: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
+ zerver/management/commands/makemessages.py:280:27: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
linter/all-rules/large/dataset.py          1.00     15.0±0.53ms     2.7 MB/sec    1.00     14.9±0.59ms     2.7 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.8±0.12ms     4.4 MB/sec    1.07      4.1±0.13ms     4.1 MB/sec
linter/all-rules/numpy/globals.py          1.00   544.2±33.72µs     5.4 MB/sec    1.04   563.7±26.56µs     5.2 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.8±0.27ms     3.8 MB/sec    1.03      7.0±0.24ms     3.6 MB/sec
linter/default-rules/large/dataset.py      1.00      8.0±0.22ms     5.1 MB/sec    1.10      8.7±0.39ms     4.7 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.05  1932.2±79.25µs     8.6 MB/sec    1.00  1847.5±51.59µs     9.0 MB/sec
linter/default-rules/numpy/globals.py      1.00    212.0±9.44µs    13.9 MB/sec    1.07    225.8±8.72µs    13.1 MB/sec
linter/default-rules/pydantic/types.py     1.00      4.0±0.20ms     6.5 MB/sec    1.03      4.1±0.25ms     6.3 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
linter/all-rules/large/dataset.py          1.00     14.6±0.12ms     2.8 MB/sec    1.00     14.6±0.09ms     2.8 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.0±0.04ms     4.2 MB/sec    1.00      4.0±0.04ms     4.1 MB/sec
linter/all-rules/numpy/globals.py          1.00    520.1±5.45µs     5.7 MB/sec    1.00   520.0±10.88µs     5.7 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.6±0.05ms     3.9 MB/sec    1.00      6.5±0.08ms     3.9 MB/sec
linter/default-rules/large/dataset.py      1.00      8.0±0.06ms     5.1 MB/sec    1.03      8.3±0.21ms     4.9 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1779.8±22.65µs     9.4 MB/sec    1.02  1811.9±32.87µs     9.2 MB/sec
linter/default-rules/numpy/globals.py      1.00    196.2±2.94µs    15.0 MB/sec    1.00    196.9±2.54µs    15.0 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.7±0.04ms     6.8 MB/sec    1.01      3.8±0.05ms     6.7 MB/sec

@dhruvmanila
Copy link
Member Author

There are a few cases which I've missed, let me look into them.

@dhruvmanila dhruvmanila marked this pull request as draft March 19, 2023 10:36
@dhruvmanila dhruvmanila marked this pull request as ready for review March 19, 2023 11:35
@Skylion007
Copy link

Thanks for doing, I gave a pass at adding it myself, but I don't have a lot of experience with RustLang or the Ruff codebase.

@dhruvmanila
Copy link
Member Author

dhruvmanila commented Mar 19, 2023

  • I've updated with separating out the dict and list/set part with a helper function to add a diagnostic.
  • The name of the existing function has been changed to unnecessary_list_set_comprehension to better reflect the purpose.
  • Add documentation for the rule. Will it be auto-generated for the website?

I'm not sure about the merge strategy used here, so should I rebase and squash relevant commits together?

@charliermarsh
Copy link
Member

Great, thanks! Will take a look today.

Add documentation for the rule. Will it be auto-generated for the website?

Yup!

@charliermarsh charliermarsh enabled auto-merge (squash) March 19, 2023 18:31
@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Mar 19, 2023
@charliermarsh charliermarsh merged commit 3a65af4 into astral-sh:main Mar 19, 2023
10 checks passed
@charliermarsh
Copy link
Member

Thanks for this! Sorry, I missed your last question. We almost always squash-and-merge to maintain a 1:1 PR-to-commit equivalence, but GitHub does it for us, so no effort needed on your end.

@dhruvmanila
Copy link
Member Author

Thanks for your feedback and merging! I hope to contribute more as I go deep into Rust and the codebase 😄

@dhruvmanila dhruvmanila deleted the feat/dict-comprehension branch March 20, 2023 00:52
renovate bot added a commit to ixm-one/pytest-cmake-presets that referenced this pull request Mar 23, 2023
[![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.257` ->
`^0.0.258` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.258/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.258/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.258/compatibility-slim/0.0.257)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.258/confidence-slim/0.0.257)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>charliermarsh/ruff</summary>

###
[`v0.0.258`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.258)

[Compare
Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.257...v0.0.258)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

##### Rules

- \[`flake8-comprehensions`] Update `C416` with dict comprehension
(autofixable) by [@&#8203;dhruvmanila](https://togithub.com/dhruvmanila)
in
[astral-sh/ruff#3605
- \[`pylint`]: Implement `assert-on-string-literal` (`W0129`) by
[@&#8203;latonis](https://togithub.com/latonis) in
[astral-sh/ruff#3610
- \[`pyupgrade`] Convert single-argument %-style format calls by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3600
- \[`pyupgrade`] Flag PEP 585 and PEP 604 violations in quoted
annotations by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3593
- \[`pyupgrade`] Enable autofix for annotations within 'simple' string
literals by [@&#8203;charliermarsh](https://togithub.com/charliermarsh)
in
[astral-sh/ruff#3657
- \[`pyflakes`] Add autofix functionality for `F523`
([#&#8203;3613](https://togithub.com/charliermarsh/ruff/issues/3613)) by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3613
- \[`flake8-bandit`]: Implement deny-list rules for suspicious member
calls by [@&#8203;colin99d](https://togithub.com/colin99d) in
[astral-sh/ruff#3239
- \[`flake8-annotations`] Add autofix for `ANN204` with magic methods by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3633
- \[`pylint`] Implement `binary-op-exception` (`PLW0711`) by
[@&#8203;latonis](https://togithub.com/latonis) in
[astral-sh/ruff#3639
- \[`flake8-django`]: Implement rule DJ012 by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[astral-sh/ruff#3659

##### Bug Fixes

- Check exclusions prior to resolving `pyproject.toml` files by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3588
- Fix D417 false positive by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3596
- Avoid removing comment hash for noqa's with trailing content by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3589
- Avoid panics for implicitly-concatenated docstrings by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3584
- Fix infinite loop due to rules `D207` & `W605` by
[@&#8203;vlindhol](https://togithub.com/vlindhol) in
[astral-sh/ruff#3609
- Avoid trimming escaped whitespace in D210 by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3635
- Handle `UP032` autofix with adjacent keywords by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3636
- Consider same-site fixes to be overlapping by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3638
- Avoid `RUF007` fixes for more than two arguments by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3654
- Allow `pairwise` diagnostics for `zip(..., strict=True)` by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3669
- isort: fix bad interaction between `force-sort-within-sections` and
`force-to-top` by [@&#8203;bluetech](https://togithub.com/bluetech) in
[astral-sh/ruff#3645
- Gracefully handle lint panics by
[@&#8203;MichaReiser](https://togithub.com/MichaReiser) in
[astral-sh/ruff#3509
- Fix TRY300 false positive by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3634
- Avoid raising PEP 604 errors with forward-referenced members by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3640
- Avoid attempting infinite `open` fix with re-bound builtin by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3650
- Check indentation level when executing E231 by
[@&#8203;kyoto7250](https://togithub.com/kyoto7250) in
[astral-sh/ruff#3668
- Flag, but don't fix, unused imports (`F401`) in `ModuleNotFoundError`
blocks by [@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3658

#### New Contributors

- [@&#8203;Rogdham](https://togithub.com/Rogdham) made their first
contribution in
[astral-sh/ruff#3607
- [@&#8203;vlindhol](https://togithub.com/vlindhol) made their first
contribution in
[astral-sh/ruff#3609
- [@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) made their
first contribution in
[astral-sh/ruff#3605
- [@&#8203;luke396](https://togithub.com/luke396) made their first
contribution in
[astral-sh/ruff#3604
- [@&#8203;fuziontech](https://togithub.com/fuziontech) made their first
contribution in
[astral-sh/ruff#3641

**Full Changelog**:
astral-sh/ruff@v0.0.257...v0.0.258

</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:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNy4xIiwidXBkYXRlZEluVmVyIjoiMzUuMTcuMSJ9-->

Signed-off-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot added a commit to allenporter/flux-local that referenced this pull request Mar 25, 2023
[![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.257` ->
`==0.0.259` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.259/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.259/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.259/compatibility-slim/0.0.257)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.259/confidence-slim/0.0.257)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>charliermarsh/ruff</summary>

###
[`v0.0.259`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.259)

[Compare
Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.258...v0.0.259)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### Summary

Follow-up release to `v0.0.258` to fix an issue related to rule
resolution via `select` and `ignore`.

#### What's Changed

##### Bug Fixes

- Fix RuleSet.remove by
[@&#8203;MichaReiser](https://togithub.com/MichaReiser) in
[astral-sh/ruff#3685
- Respect all rule-exemption sources when suppressing parser errors by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3665
- Avoid nested loops in `missing_whitespace` by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3688

**Full Changelog**:
astral-sh/ruff@v0.0.258...v0.0.259

###
[`v0.0.258`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.258)

[Compare
Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.257...v0.0.258)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

##### Rules

- \[`flake8-comprehensions`] Update `C416` with dict comprehension
(autofixable) by [@&#8203;dhruvmanila](https://togithub.com/dhruvmanila)
in
[astral-sh/ruff#3605
- \[`pylint`]: Implement `assert-on-string-literal` (`W0129`) by
[@&#8203;latonis](https://togithub.com/latonis) in
[astral-sh/ruff#3610
- \[`pyupgrade`] Convert single-argument %-style format calls by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3600
- \[`pyupgrade`] Flag PEP 585 and PEP 604 violations in quoted
annotations by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3593
- \[`pyupgrade`] Enable autofix for annotations within 'simple' string
literals by [@&#8203;charliermarsh](https://togithub.com/charliermarsh)
in
[astral-sh/ruff#3657
- \[`pyflakes`] Add autofix functionality for `F523`
([#&#8203;3613](https://togithub.com/charliermarsh/ruff/issues/3613)) by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3613
- \[`flake8-bandit`]: Implement deny-list rules for suspicious member
calls by [@&#8203;colin99d](https://togithub.com/colin99d) in
[astral-sh/ruff#3239
- \[`flake8-annotations`] Add autofix for `ANN204` with magic methods by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3633
- \[`pylint`] Implement `binary-op-exception` (`PLW0711`) by
[@&#8203;latonis](https://togithub.com/latonis) in
[astral-sh/ruff#3639
- \[`flake8-django`]: Implement rule DJ012 by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[astral-sh/ruff#3659

##### Bug Fixes

- Check exclusions prior to resolving `pyproject.toml` files by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3588
- Fix D417 false positive by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3596
- Avoid removing comment hash for noqa's with trailing content by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3589
- Avoid panics for implicitly-concatenated docstrings by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3584
- Fix infinite loop due to rules `D207` & `W605` by
[@&#8203;vlindhol](https://togithub.com/vlindhol) in
[astral-sh/ruff#3609
- Avoid trimming escaped whitespace in D210 by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3635
- Handle `UP032` autofix with adjacent keywords by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3636
- Consider same-site fixes to be overlapping by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3638
- Avoid `RUF007` fixes for more than two arguments by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3654
- Allow `pairwise` diagnostics for `zip(..., strict=True)` by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3669
- isort: fix bad interaction between `force-sort-within-sections` and
`force-to-top` by [@&#8203;bluetech](https://togithub.com/bluetech) in
[astral-sh/ruff#3645
- Gracefully handle lint panics by
[@&#8203;MichaReiser](https://togithub.com/MichaReiser) in
[astral-sh/ruff#3509
- Fix TRY300 false positive by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[astral-sh/ruff#3634
- Avoid raising PEP 604 errors with forward-referenced members by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3640
- Avoid attempting infinite `open` fix with re-bound builtin by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3650
- Check indentation level when executing E231 by
[@&#8203;kyoto7250](https://togithub.com/kyoto7250) in
[astral-sh/ruff#3668
- Flag, but don't fix, unused imports (`F401`) in `ModuleNotFoundError`
blocks by [@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#3658

#### New Contributors

- [@&#8203;Rogdham](https://togithub.com/Rogdham) made their first
contribution in
[astral-sh/ruff#3607
- [@&#8203;vlindhol](https://togithub.com/vlindhol) made their first
contribution in
[astral-sh/ruff#3609
- [@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) made their
first contribution in
[astral-sh/ruff#3605
- [@&#8203;luke396](https://togithub.com/luke396) made their first
contribution in
[astral-sh/ruff#3604
- [@&#8203;fuziontech](https://togithub.com/fuziontech) made their first
contribution in
[astral-sh/ruff#3641

**Full Changelog**:
astral-sh/ruff@v0.0.257...v0.0.258

</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:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNC4yIiwidXBkYXRlZEluVmVyIjoiMzUuMTQuMiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update C416 rule with dict comprehensions and make autofixable
3 participants