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

[refurb] Support itemgetter in reimplemented-operator (FURB118) #10526

Merged
merged 4 commits into from
Apr 7, 2024

Conversation

alex-700
Copy link
Contributor

Summary

Lint about function like expressions which are equivalent to operator.itemgetter.
See: #1348 (comment)

Test Plan

cargo test

@alex-700 alex-700 force-pushed the latyshev/furb118-itemgetter branch from 944e9b8 to e23a66a Compare March 22, 2024 16:19
Copy link
Contributor

github-actions bot commented Mar 22, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+95 -0 violations, +0 -0 fixes in 5 projects; 39 projects unchanged)

apache/airflow (+28 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ airflow/providers/amazon/aws/hooks/redshift_cluster.py:135:28: FURB118 [*] Use `operator.itemgetter("SnapshotCreateTime")` instead of defining a lambda
+ airflow/providers/weaviate/hooks/weaviate.py:842:23: FURB118 [*] Use `operator.itemgetter(uuid_column)` instead of defining a lambda
+ airflow/providers_manager.py:1297:59: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ airflow/providers_manager.py:1301:59: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ dev/stats/get_important_pr_candidates.py:387:69: FURB118 [*] Use `operator.itemgetter(1)` instead of defining a lambda
+ docs/conf.py:578:26: FURB118 [*] Use `operator.itemgetter("name")` instead of defining a lambda
+ docs/exts/docs_build/fetch_inventories.py:150:33: FURB118 [*] Use `operator.itemgetter(1)` instead of defining a lambda
+ docs/exts/operators_and_hooks_ref.py:219:41: FURB118 [*] Use `operator.itemgetter("name")` instead of defining a lambda
+ docs/exts/operators_and_hooks_ref.py:316:52: FURB118 [*] Use `operator.itemgetter("object_path")` instead of defining a lambda
+ docs/exts/operators_and_hooks_ref.py:324:41: FURB118 [*] Use `operator.itemgetter("name")` instead of defining a lambda
+ docs/exts/providers_extensions.py:169:82: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ tests/api_experimental/client/test_local_client.py:198:53: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ tests/operators/test_python.py:1293:9: FURB118 Use `operator.itemgetter("ds")` instead of defining a function
+ tests/operators/test_python.py:808:9: FURB118 Use `operator.itemgetter("ds")` instead of defining a function
... 14 additional changes omitted for project

bokeh/bokeh (+7 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ examples/topics/categorical/les_mis.py:18:61: FURB118 [*] Use `operator.itemgetter('group')` instead of defining a lambda
+ src/bokeh/palettes.py:1945:56: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ src/bokeh/resources.py:461:73: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ src/bokeh/sampledata/browsers.py:76:35: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ src/bokeh/util/compiler.py:486:49: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ src/bokeh/util/compiler.py:577:35: FURB118 [*] Use `operator.itemgetter(1)` instead of defining a lambda
+ src/bokeh/util/compiler.py:578:35: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda

rotki/rotki (+12 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ rotkehlchen/api/v1/schemas.py:1989:52: FURB118 [*] Use `operator.itemgetter('address')` instead of defining a lambda
+ rotkehlchen/api/v1/schemas.py:2016:52: FURB118 [*] Use `operator.itemgetter('address')` instead of defining a lambda
+ rotkehlchen/chain/evm/decoding/decoder.py:384:24: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ rotkehlchen/db/search_assets.py:123:79: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ rotkehlchen/exchanges/binance.py:1187:31: FURB118 [*] Use `operator.itemgetter('time')` instead of defining a lambda
+ rotkehlchen/exchanges/bitfinex.py:385:34: FURB118 [*] Use `operator.itemgetter(id_index)` instead of defining a lambda
+ rotkehlchen/exchanges/poloniex.py:189:56: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ rotkehlchen/externalapis/etherscan.py:74:46: FURB118 [*] Use `operator.itemgetter(1)` instead of defining a lambda
+ rotkehlchen/globaldb/cache.py:233:27: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ rotkehlchen/tests/api/test_manually_tracked_balances.py:76:32: FURB118 [*] Use `operator.itemgetter('label')` instead of defining a lambda
... 2 additional changes omitted for project

zulip/zulip (+45 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ analytics/views/stats.py:491:82: FURB118 [*] Use `operator.itemgetter(1)` instead of defining a lambda
+ corporate/views/support.py:485:39: FURB118 [*] Use `operator.itemgetter("display_order")` instead of defining a lambda
+ tools/setup/emoji/emoji_setup_utils.py:105:1: FURB118 Use `operator.itemgetter("has_img_google")` instead of defining a function
+ zerver/actions/default_streams.py:194:62: FURB118 [*] Use `operator.itemgetter("name")` instead of defining a lambda
+ zerver/actions/message_send.py:436:9: FURB118 [*] Use `operator.itemgetter("enable_online_push_notifications")` instead of defining a lambda
+ zerver/actions/message_send.py:455:9: FURB118 [*] Use `operator.itemgetter("long_term_idle")` instead of defining a lambda
+ zerver/context_processors.py:285:68: FURB118 [*] Use `operator.itemgetter("display_order")` instead of defining a lambda
+ zerver/lib/default_streams.py:32:37: FURB118 [*] Use `operator.itemgetter("name")` instead of defining a lambda
+ zerver/lib/display_recipient.py:109:5: FURB118 Use `operator.itemgetter("recipient_id")` instead of defining a function
+ zerver/lib/display_recipient.py:112:5: FURB118 Use `operator.itemgetter("name")` instead of defining a function
+ zerver/lib/display_recipient.py:143:24: FURB118 [*] Use `operator.itemgetter(0)` instead of defining a lambda
+ zerver/lib/display_recipient.py:144:16: FURB118 [*] Use `operator.itemgetter(1)` instead of defining a lambda
+ zerver/lib/display_recipient.py:67:1: FURB118 Use `operator.itemgetter("id")` instead of defining a function
+ zerver/lib/email_notifications.py:651:43: FURB118 [*] Use `operator.itemgetter(1)` instead of defining a lambda
+ zerver/lib/events.py:1083:44: FURB118 [*] Use `operator.itemgetter("name")` instead of defining a lambda
+ zerver/lib/events.py:1084:48: FURB118 [*] Use `operator.itemgetter("name")` instead of defining a lambda
+ zerver/lib/events.py:1086:43: FURB118 [*] Use `operator.itemgetter("name")` instead of defining a lambda
+ zerver/lib/events.py:1438:49: FURB118 [*] Use `operator.itemgetter("id")` instead of defining a lambda
+ zerver/lib/events.py:1703:60: FURB118 [*] Use `operator.itemgetter("user_id")` instead of defining a lambda
+ zerver/lib/events.py:837:21: FURB118 [*] Use `operator.itemgetter("scheduled_delivery_timestamp")` instead of defining a lambda
+ zerver/lib/events.py:853:33: FURB118 [*] Use `operator.itemgetter("scheduled_delivery_timestamp")` instead of defining a lambda
+ zerver/lib/export.py:2444:46: FURB118 [*] Use `operator.itemgetter("id")` instead of defining a lambda
+ zerver/lib/export.py:381:24: FURB118 [*] Use `operator.itemgetter("id")` instead of defining a lambda
... 22 additional changes omitted for project

indico/indico (+3 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ indico/modules/events/abstracts/forms.py:564:55: FURB118 [*] Use `operator.itemgetter(slice(3, None))` instead of defining a lambda
+ indico/modules/events/abstracts/forms.py:598:55: FURB118 [*] Use `operator.itemgetter(slice(3, None))` instead of defining a lambda
+ indico/modules/events/editing/schemas.py:471:34: FURB118 [*] Use `operator.itemgetter('source', 'code')` instead of defining a lambda

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
FURB118 95 95 0 0 0

@charliermarsh charliermarsh self-requested a review April 7, 2024 00:54
@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Apr 7, 2024
@charliermarsh charliermarsh self-assigned this Apr 7, 2024
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

Thanks!

@charliermarsh charliermarsh changed the title [refurb] Support itemgetter in reimplemented_operator (FURB118) lint [refurb] Support itemgetter in reimplemented-operator (FURB118) Apr 7, 2024
@charliermarsh charliermarsh added the preview Related to preview mode features label Apr 7, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) April 7, 2024 02:21
@charliermarsh charliermarsh merged commit 6050bab into astral-sh:main Apr 7, 2024
17 checks passed
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request Apr 12, 2024
…`) (astral-sh#10526)

## Summary
Lint about function like expressions which are equivalent to
`operator.itemgetter`.
See:
astral-sh#1348 (comment)

## Test Plan
cargo test
@ThiefMaster
Copy link
Contributor

-return groupby(list(self.iter_choices()), key=lambda x: x[3:])
+return groupby(list(self.iter_choices()), key=operator.itemgetter(slice(3, None)))

Not a fan of this change tbh. While it may have slightly better performance, it's much less readable...

It's also much longer, but that's mainly because it prefers import operator instead of from operator import ..., which is probably unrelated to your PR.

That aside I really like having a lint rule that prefers itemgetter over lambdas. Just not for slices...

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