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

[pylint] Implement unnecessary-dunder-call (C2801) #9166

Merged
merged 6 commits into from
Jan 3, 2024

Conversation

diceroll123
Copy link
Contributor

Summary

Implements C2801/unnecessary-dunder-calls

There are more that this could cover, but the implementations get a little less straightforward and ugly. Might come back to it in a future PR, or someone else can!

See: #970

Test Plan

cargo test

@diceroll123 diceroll123 force-pushed the add-C2801 branch 3 times, most recently from 42ad4f3 to d8d25f7 Compare December 16, 2023 23:01
Copy link
Contributor

github-actions bot commented Dec 16, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+491 -0 violations, +0 -0 fixes in 12 projects; 29 projects unchanged)

DisnakeDev/disnake (+17 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ disnake/activity.py:479:20: PLC2801 [*] Unnecessary dunder call to `__eq__`. Use `==` operator.
+ disnake/activity.py:591:20: PLC2801 [*] Unnecessary dunder call to `__eq__`. Use `==` operator.
+ disnake/activity.py:695:20: PLC2801 [*] Unnecessary dunder call to `__eq__`. Use `==` operator.
+ disnake/activity.py:870:20: PLC2801 [*] Unnecessary dunder call to `__eq__`. Use `==` operator.
+ disnake/colour.py:68:20: PLC2801 [*] Unnecessary dunder call to `__eq__`. Use `==` operator.
+ disnake/context_managers.py:60:16: PLC2801 Unnecessary dunder call to `__enter__`
+ disnake/emoji.py:128:20: PLC2801 [*] Unnecessary dunder call to `__eq__`. Use `==` operator.
+ disnake/ext/commands/params.py:1348:20: PLC2801 Unnecessary dunder call to `__get__`. Use `get` method.
+ disnake/flags.py:153:20: PLC2801 [*] Unnecessary dunder call to `__eq__`. Use `==` operator.
+ disnake/member.py:359:20: PLC2801 [*] Unnecessary dunder call to `__eq__`. Use `==` operator.
... 7 additional changes omitted for project

aiven/aiven-client (+3 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ aiven/client/argx.py:189:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ aiven/client/cli.py:141:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ aiven/client/client.py:34:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.

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

ruff check --no-cache --exit-zero --preview --select ALL

+ airflow/configuration.py:1887:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ airflow/configuration.py:1962:36: PLC2801 Unnecessary dunder call to `__fspath__`. Use `os.fspath` function.
+ airflow/configuration.py:1966:62: PLC2801 Unnecessary dunder call to `__fspath__`. Use `os.fspath` function.
+ airflow/configuration.py:1974:41: PLC2801 Unnecessary dunder call to `__fspath__`. Use `os.fspath` function.
+ airflow/configuration.py:1979:65: PLC2801 Unnecessary dunder call to `__fspath__`. Use `os.fspath` function.
+ airflow/configuration.py:1997:39: PLC2801 Unnecessary dunder call to `__fspath__`. Use `os.fspath` function.
+ airflow/models/baseoperator.py:192:16: PLC2801 Unnecessary dunder call to `__get__`. Use `get` method.
+ airflow/models/taskmixin.py:109:9: PLC2801 [*] Unnecessary dunder call to `__lshift__`. Use `<<` operator.
+ airflow/models/taskmixin.py:114:9: PLC2801 [*] Unnecessary dunder call to `__rshift__`. Use `>>` operator.
+ airflow/models/xcom.py:724:21: PLC2801 Unnecessary dunder call to `__enter__`
+ airflow/providers/elasticsearch/log/es_response.py:57:20: PLC2801 Unnecessary dunder call to `__getitem__`. Access item via subscript.
+ airflow/providers/fab/auth_manager/cli_commands/user_command.py:167:44: PLC2801 Unnecessary dunder call to `__getattribute__`. Access attribute directly or use getattr built-in function..
+ airflow/providers/fab/auth_manager/cli_commands/user_command.py:60:66: PLC2801 Unnecessary dunder call to `__getattribute__`. Access attribute directly or use getattr built-in function..
... 117 additional changes omitted for project

aws/aws-sam-cli (+56 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ samcli/commands/exceptions.py:28:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ samcli/commands/exceptions.py:47:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ samcli/commands/local/lib/debug_context.py:31:16: PLC2801 [*] Unnecessary dunder call to `__bool__`. Use `bool()` builtin.
+ samcli/hook_packages/terraform/hooks/prepare/exceptions.py:19:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ samcli/hook_packages/terraform/hooks/prepare/exceptions.py:34:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ samcli/hook_packages/terraform/hooks/prepare/exceptions.py:392:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ samcli/hook_packages/terraform/hooks/prepare/exceptions.py:51:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ samcli/hook_packages/terraform/hooks/prepare/exceptions.py:74:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ samcli/lib/cookiecutter/exceptions.py:9:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ samcli/lib/docker/log_streamer.py:20:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
... 46 additional changes omitted for project

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

ruff check --no-cache --exit-zero --preview --select ALL

+ src/bokeh/core/property/descriptors.py:394:16: PLC2801 Unnecessary dunder call to `__get__`. Use `get` method.
+ src/bokeh/core/property/descriptors.py:444:21: PLC2801 Unnecessary dunder call to `__get__`. Use `get` method.
+ src/bokeh/core/property/descriptors.py:652:17: PLC2801 Unnecessary dunder call to `__get__`. Use `get` method.
+ src/bokeh/core/property/descriptors.py:944:17: PLC2801 Unnecessary dunder call to `__set__`. Use subscript assignment.
+ src/bokeh/core/property/wrappers.py:476:17: PLC2801 Unnecessary dunder call to `__setitem__`. Use subscript assignment.
+ src/bokeh/embed/util.py:276:16: PLC2801 Unnecessary dunder call to `__getitem__`. Access item via subscript.
+ src/bokeh/models/plots.py:909:20: PLC2801 Unnecessary dunder call to `__getattribute__`. Access attribute directly or use getattr built-in function..
+ tests/unit/bokeh/core/property/test_descriptors.py:105:13: PLC2801 Unnecessary dunder call to `__set__`. Use subscript assignment.
+ tests/unit/bokeh/core/property/test_descriptors.py:98:13: PLC2801 Unnecessary dunder call to `__get__`. Use `get` method.
+ tests/unit/bokeh/core/property/test_wrappers__property.py:550:12: PLC2801 Unnecessary dunder call to `__copy__`. Use `copy.copy()` function.
... 2 additional changes omitted for project

freedomofpress/securedrop (+20 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ journalist_gui/journalist_gui/SecureDropUpdater.py:125:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ journalist_gui/journalist_gui/SecureDropUpdater.py:49:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ journalist_gui/journalist_gui/SecureDropUpdater.py:89:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ securedrop/journalist_app/sessions.py:31:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ securedrop/pretty_bad_protocol/_meta.py:677:54: PLC2801 [*] Unnecessary dunder call to `__repr__`. Use `repr()` builtin.
+ securedrop/pretty_bad_protocol/_meta.py:688:59: PLC2801 [*] Unnecessary dunder call to `__repr__`. Use `repr()` builtin.
+ securedrop/pretty_bad_protocol/_parsers.py:1774:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ securedrop/pretty_bad_protocol/_util.py:364:11: PLC2801 [*] Unnecessary dunder call to `__str__`. Use `str()` builtin.
+ securedrop/tests/migrations/migration_a9fe328b053a.py:50:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
+ securedrop/tests/migrations/migration_a9fe328b053a.py:72:9: PLC2801 Unnecessary dunder call to `__init__`. Instantiate class directly.
... 10 additional changes omitted for project

fronzbot/blinkpy (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ blinkpy/sync_module.py:759:16: PLC2801 [*] Unnecessary dunder call to `__repr__`. Use `repr()` builtin.

ibis-project/ibis (+21 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ ibis/common/bases.py:198:13: PLC2801 Unnecessary dunder call to `__setattr__`. Mutate attribute directly or use setattr built-in function..
+ ibis/common/bases.py:212:13: PLC2801 Unnecessary dunder call to `__setattr__`. Mutate attribute directly or use setattr built-in function..
+ ibis/common/bases.py:239:13: PLC2801 Unnecessary dunder call to `__setattr__`. Mutate attribute directly or use setattr built-in function..
+ ibis/common/bases.py:241:9: PLC2801 Unnecessary dunder call to `__setattr__`. Mutate attribute directly or use setattr built-in function..
+ ibis/common/bases.py:245:13: PLC2801 Unnecessary dunder call to `__setattr__`. Mutate attribute directly or use setattr built-in function..
+ ibis/common/bases.py:247:9: PLC2801 Unnecessary dunder call to `__setattr__`. Mutate attribute directly or use setattr built-in function..
+ ibis/common/caching.py:39:9: PLC2801 Unnecessary dunder call to `__setattr__`. Mutate attribute directly or use setattr built-in function..
+ ibis/common/collections.py:229:43: PLC2801 [*] Unnecessary dunder call to `__ge__`. Use `>=` operator.
+ ibis/common/collections.py:240:43: PLC2801 [*] Unnecessary dunder call to `__le__`. Use `<=` operator.
+ ibis/common/collections.py:295:9: PLC2801 Unnecessary dunder call to `__setattr__`. Mutate attribute directly or use setattr built-in function..
... 11 additional changes omitted for project

milvus-io/pymilvus (+13 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ pymilvus/client/abstract.py:179:16: PLC2801 [*] Unnecessary dunder call to `__str__`. Use `str()` builtin.
+ pymilvus/client/abstract.py:282:16: PLC2801 [*] Unnecessary dunder call to `__str__`. Use `str()` builtin.
+ pymilvus/client/abstract.py:360:16: PLC2801 [*] Unnecessary dunder call to `__str__`. Use `str()` builtin.
+ pymilvus/client/abstract.py:627:35: PLC2801 [*] Unnecessary dunder call to `__len__`. Use `len()` builtin.
+ pymilvus/client/abstract.py:627:69: PLC2801 [*] Unnecessary dunder call to `__len__`. Use `len()` builtin.
+ pymilvus/client/abstract.py:632:20: PLC2801 [*] Unnecessary dunder call to `__len__`. Use `len()` builtin.
+ pymilvus/client/abstract.py:639:30: PLC2801 [*] Unnecessary dunder call to `__len__`. Use `len()` builtin.
+ pymilvus/client/abstract.py:641:20: PLC2801 Unnecessary dunder call to `__getitem__`. Access item via subscript.
+ pymilvus/client/abstract.py:648:34: PLC2801 Unnecessary dunder call to `__getitem__`. Access item via subscript.
+ pymilvus/client/prepare.py:1177:24: PLC2801 [*] Unnecessary dunder call to `__str__`. Use `str()` builtin.
... 3 additional changes omitted for project

... Truncated remaining completed project reports due to GitHub comment length restrictions

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
PLC2801 490 490 0 0 0
E711 1 1 0 0 0

@diceroll123 diceroll123 marked this pull request as draft December 16, 2023 23:50
@diceroll123 diceroll123 force-pushed the add-C2801 branch 3 times, most recently from 504f0cf to 2af5c87 Compare December 17, 2023 17:42
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.

Reviewing now...

@charliermarsh charliermarsh added rule Implementing or modifying a lint rule preview Related to preview mode features labels Jan 3, 2024
@charliermarsh charliermarsh changed the title [pylint] - implement C2801/unnecessary-dunder-calls [pylint] Implement unnecessary-dunder-calls (C2801) Jan 3, 2024
@charliermarsh charliermarsh changed the title [pylint] Implement unnecessary-dunder-calls (C2801) [pylint] Implement unnecessary-dunder-call (C2801) Jan 3, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) January 3, 2024 18:04
@charliermarsh charliermarsh merged commit e3ad163 into astral-sh:main Jan 3, 2024
16 checks passed
charliermarsh pushed a commit that referenced this pull request Jan 12, 2024
<!--
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

Fix the message for `__aenter__ ` in PLC2801 (introduced in
#9166)
There is no `aenter` builtin in Python, so the current message is
misleading.
I take the message from original lint
https://github.com/pylint-dev/pylint/blob/main/pylint/constants.py#L211

P.S. I think here should be more accurate synchronization with original
lint (e.g. the current implementation will not lint `__enter__` on my
first sight), but it is out-of-scope of this change.

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

## Test Plan

<!-- How was it tested? -->
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.

2 participants