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] removed dunder methods in Python 3 (PLW3201) #13194

Merged
merged 7 commits into from
Sep 4, 2024

Conversation

iamlucasvieira
Copy link
Contributor

@iamlucasvieira iamlucasvieira commented Sep 1, 2024

Summary

Add message for deprecated dunder methods not supported in Python 3

This PR addresses issue #12883 by adding custom messages in PLW3201 for dunder methods that were deprecated in Python 2 and are no longer valid in Python 3. The message is displayed for the dunder methods listed in #12607 and additional methods that are no longer part of Python 3 documentation:

  • __iop__
  • __rop__
  • __op__

fixes #12883

Test Plan

New snapshot added and cargo test

Add message for when the dunder method name is no longer valid in Python
3.
Copy link
Contributor

github-actions bot commented Sep 1, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+115 -115 violations, +0 -0 fixes in 9 projects; 45 projects unchanged)

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

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

- disnake/enums.py:168:9: PLW3201 Bad or misspelled dunder method name `__members__`
+ disnake/enums.py:168:9: PLW3201 Dunder method `__members__` has no special meaning in Python 3

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

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

- airflow/decorators/base.py:390:9: PLW3201 Bad or misspelled dunder method name `__wrapped__`
+ airflow/decorators/base.py:390:9: PLW3201 Dunder method `__wrapped__` has no special meaning in Python 3
- airflow/decorators/base.py:594:9: PLW3201 Bad or misspelled dunder method name `__wrapped__`
+ airflow/decorators/base.py:594:9: PLW3201 Dunder method `__wrapped__` has no special meaning in Python 3
- airflow/providers/databricks/operators/databricks_repos.py:106:9: PLW3201 Bad or misspelled dunder method name `__detect_repo_provider__`
+ airflow/providers/databricks/operators/databricks_repos.py:106:9: PLW3201 Dunder method `__detect_repo_provider__` has no special meaning in Python 3
- airflow/providers/fab/auth_manager/models/__init__.py:94:9: PLW3201 Bad or misspelled dunder method name `__neq__`
+ airflow/providers/fab/auth_manager/models/__init__.py:94:9: PLW3201 Dunder method `__neq__` has no special meaning in Python 3

apache/superset (+3 -3 violations, +0 -0 fixes)

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

- superset/migrations/shared/security_converge.py:68:9: PLW3201 Bad or misspelled dunder method name `__neq__`
+ superset/migrations/shared/security_converge.py:68:9: PLW3201 Dunder method `__neq__` has no special meaning in Python 3
- superset/migrations/versions/2020-09-24_12-04_3fbbc6e8d654_fix_data_access_permissions_for_virtual_.py:65:9: PLW3201 Bad or misspelled dunder method name `__neq__`
+ superset/migrations/versions/2020-09-24_12-04_3fbbc6e8d654_fix_data_access_permissions_for_virtual_.py:65:9: PLW3201 Dunder method `__neq__` has no special meaning in Python 3
- tests/integration_tests/fixtures/pyodbcRow.py:21:9: PLW3201 Bad or misspelled dunder method name `__name__`
+ tests/integration_tests/fixtures/pyodbcRow.py:21:9: PLW3201 Dunder method `__name__` has no special meaning in Python 3

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

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

- samcli/commands/local/lib/debug_context.py:30:9: PLW3201 Bad or misspelled dunder method name `__nonzero__`
+ samcli/commands/local/lib/debug_context.py:30:9: PLW3201 Dunder method `__nonzero__` has no special meaning in Python 3

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

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

- src/bokeh/io/notebook.py:129:9: PLW3201 Bad or misspelled dunder method name `_repr_html_`
+ src/bokeh/io/notebook.py:129:9: PLW3201 Dunder method `_repr_html_` has no special meaning in Python 3
- src/bokeh/model/model.py:602:9: PLW3201 Bad or misspelled dunder method name `_repr_html_`
+ src/bokeh/model/model.py:602:9: PLW3201 Dunder method `_repr_html_` has no special meaning in Python 3
- tests/unit/bokeh/core/test_serialization.py:806:17: PLW3201 Bad or misspelled dunder method name `__array__`
+ tests/unit/bokeh/core/test_serialization.py:806:17: PLW3201 Dunder method `__array__` has no special meaning in Python 3

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

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

- securedrop/pretty_bad_protocol/_meta.py:227:9: PLW3201 Bad or misspelled dunder method name `__remove_path__`
+ securedrop/pretty_bad_protocol/_meta.py:227:9: PLW3201 Dunder method `__remove_path__` has no special meaning in Python 3
- securedrop/pretty_bad_protocol/_parsers.py:1007:9: PLW3201 Bad or misspelled dunder method name `__nonzero__`
+ securedrop/pretty_bad_protocol/_parsers.py:1007:9: PLW3201 Dunder method `__nonzero__` has no special meaning in Python 3
- securedrop/pretty_bad_protocol/_parsers.py:1115:9: PLW3201 Bad or misspelled dunder method name `__nonzero__`
+ securedrop/pretty_bad_protocol/_parsers.py:1115:9: PLW3201 Dunder method `__nonzero__` has no special meaning in Python 3
- securedrop/pretty_bad_protocol/_parsers.py:1313:9: PLW3201 Bad or misspelled dunder method name `__nonzero__`
+ securedrop/pretty_bad_protocol/_parsers.py:1313:9: PLW3201 Dunder method `__nonzero__` has no special meaning in Python 3
- securedrop/pretty_bad_protocol/_parsers.py:1417:9: PLW3201 Bad or misspelled dunder method name `__nonzero__`
+ securedrop/pretty_bad_protocol/_parsers.py:1417:9: PLW3201 Dunder method `__nonzero__` has no special meaning in Python 3
... 4 additional changes omitted for project

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

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

- ibis/backends/__init__.py:86:9: PLW3201 Bad or misspelled dunder method name `_ipython_key_completions_`
+ ibis/backends/__init__.py:86:9: PLW3201 Dunder method `_ipython_key_completions_` has no special meaning in Python 3
- ibis/backends/__init__.py:878:9: PLW3201 Bad or misspelled dunder method name `__rich_repr__`
+ ibis/backends/__init__.py:878:9: PLW3201 Dunder method `__rich_repr__` has no special meaning in Python 3
- ibis/backends/snowflake/converter.py:34:9: PLW3201 Bad or misspelled dunder method name `__arrow_ext_serialize__`
+ ibis/backends/snowflake/converter.py:34:9: PLW3201 Dunder method `__arrow_ext_serialize__` has no special meaning in Python 3
- ibis/backends/snowflake/converter.py:38:9: PLW3201 Bad or misspelled dunder method name `__arrow_ext_deserialize__`
+ ibis/backends/snowflake/converter.py:38:9: PLW3201 Dunder method `__arrow_ext_deserialize__` has no special meaning in Python 3
- ibis/backends/snowflake/converter.py:41:9: PLW3201 Bad or misspelled dunder method name `__arrow_ext_class__`
+ ibis/backends/snowflake/converter.py:41:9: PLW3201 Dunder method `__arrow_ext_class__` has no special meaning in Python 3
- ibis/backends/snowflake/converter.py:44:9: PLW3201 Bad or misspelled dunder method name `__arrow_ext_scalar_class__`
+ ibis/backends/snowflake/converter.py:44:9: PLW3201 Dunder method `__arrow_ext_scalar_class__` has no special meaning in Python 3
- ibis/backends/sql/compilers/base.py:1196:9: PLW3201 Bad or misspelled dunder method name `__sql_name__`
+ ibis/backends/sql/compilers/base.py:1196:9: PLW3201 Dunder method `__sql_name__` has no special meaning in Python 3
- ibis/backends/sql/compilers/pyspark.py:348:9: PLW3201 Bad or misspelled dunder method name `__sql_name__`
+ ibis/backends/sql/compilers/pyspark.py:348:9: PLW3201 Dunder method `__sql_name__` has no special meaning in Python 3
- ibis/common/bases.py:104:9: PLW3201 Bad or misspelled dunder method name `__create__`
+ ibis/common/bases.py:104:9: PLW3201 Dunder method `__create__` has no special meaning in Python 3
- ibis/common/bases.py:122:9: PLW3201 Bad or misspelled dunder method name `__prohibit_inheritance__`
+ ibis/common/bases.py:122:9: PLW3201 Dunder method `__prohibit_inheritance__` has no special meaning in Python 3
- ibis/common/bases.py:147:9: PLW3201 Bad or misspelled dunder method name `__equals__`
+ ibis/common/bases.py:147:9: PLW3201 Dunder method `__equals__` has no special meaning in Python 3
- ibis/common/bases.py:213:9: PLW3201 Bad or misspelled dunder method name `__rich_repr__`
+ ibis/common/bases.py:213:9: PLW3201 Dunder method `__rich_repr__` has no special meaning in Python 3
- ibis/common/deferred.py:247:9: PLW3201 Bad or misspelled dunder method name `__create__`
+ ibis/common/deferred.py:247:9: PLW3201 Dunder method `__create__` has no special meaning in Python 3
- ibis/common/deferred.py:49:9: PLW3201 Bad or misspelled dunder method name `__coerce__`
+ ibis/common/deferred.py:49:9: PLW3201 Dunder method `__coerce__` has no special meaning in Python 3
- ibis/common/egraph.py:497:9: PLW3201 Bad or misspelled dunder method name `__argnames__`
+ ibis/common/egraph.py:497:9: PLW3201 Dunder method `__argnames__` has no special meaning in Python 3
- ibis/common/egraph.py:502:9: PLW3201 Bad or misspelled dunder method name `__args__`
+ ibis/common/egraph.py:502:9: PLW3201 Dunder method `__args__` has no special meaning in Python 3
- ibis/common/graph.py:212:9: PLW3201 Bad or misspelled dunder method name `__recreate__`
+ ibis/common/graph.py:212:9: PLW3201 Dunder method `__recreate__` has no special meaning in Python 3
- ibis/common/graph.py:218:9: PLW3201 Bad or misspelled dunder method name `__args__`
+ ibis/common/graph.py:218:9: PLW3201 Dunder method `__args__` has no special meaning in Python 3
- ibis/common/graph.py:223:9: PLW3201 Bad or misspelled dunder method name `__argnames__`
+ ibis/common/graph.py:223:9: PLW3201 Dunder method `__argnames__` has no special meaning in Python 3
- ibis/common/graph.py:227:9: PLW3201 Bad or misspelled dunder method name `__children__`
... 143 additional changes omitted for project

wntrblm/nox (+1 -1 violations, +0 -0 fixes)

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

- nox/sessions.py:1054:9: PLW3201 Bad or misspelled dunder method name `__nonzero__`
+ nox/sessions.py:1054:9: PLW3201 Dunder method `__nonzero__` has no special meaning in Python 3

pytest-dev/pytest (+4 -4 violations, +0 -0 fixes)

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

- src/_pytest/_py/path.py:337:9: PLW3201 Bad or misspelled dunder method name `__div__`
+ src/_pytest/_py/path.py:337:9: PLW3201 Dunder method `__div__` has no special meaning in Python 3
- testing/python/approx.py:780:17: PLW3201 Bad or misspelled dunder method name `__array__`
+ testing/python/approx.py:780:17: PLW3201 Dunder method `__array__` has no special meaning in Python 3
- testing/python/approx.py:800:17: PLW3201 Bad or misspelled dunder method name `__array__`
+ testing/python/approx.py:800:17: PLW3201 Dunder method `__array__` has no special meaning in Python 3
- testing/python/approx.py:807:17: PLW3201 Bad or misspelled dunder method name `__array__`
+ testing/python/approx.py:807:17: PLW3201 Dunder method `__array__` has no special meaning in Python 3

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

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PLW3201 230 115 115 0 0

@AlexWaygood AlexWaygood changed the title [pylint] depracted dunder methods in Python 3 (PLW3201) [pylint] deprecated dunder methods in Python 3 (PLW3201) Sep 1, 2024
@dscorbett
Copy link

__iop__, __rop__, and __op__ should not be included, because they didn’t exist in Python 2. They were only used in the documentation as placeholders for methods like __iadd__, __radd__, __add__, etc.

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features labels Sep 2, 2024
@MichaReiser
Copy link
Member

Thanks, this is looking great

@Skylion007
Copy link
Contributor

Shocked this isn't already covered by a pyupgrade rule

match kind {
Kind::Misspelled => format!("Bad or misspelled dunder method name `{name}`"),
Kind::RemovedInPython3 => {
format!("Python 2 or older only dunder method name `{name}`")
Copy link
Member

Choose a reason for hiding this comment

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

@AlexWaygood any suggestion on how to improve the wording here? It's kind of hard to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think removing the 'only' makes it read a bit smoother, but it might change the meaning slightly.

Copy link
Member

@AlexWaygood AlexWaygood Sep 3, 2024

Choose a reason for hiding this comment

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

Maybe something like this?

Suggested change
format!("Python 2 or older only dunder method name `{name}`")
format!("Dunder method `{name}` has no special meaning in Python 3")

Though actually, that's a pretty good description of what the problem is in both cases. I wonder if we need to distinguish between misspelled dunder methods and those that were removed in Python 3 at all, or if we could just improve the docs (like this PR already does) and use a better error message here that applies to both cases? In both cases -- whether you've misspelled a dunder or you're using one that had its special semantics removed in Python 3 -- it's not going to cause any kind of exception to define the dunder method. It's just probably not going to do what you want, because it doesn't have any special semantics attached to it anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Way clearer!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MichaReiser What do you think about a single message for both cases?

Copy link
Member

Choose a reason for hiding this comment

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

A bit dissatisfying after all the hard work you put into this but I do like the suggested message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, I also agree 😄

@MichaReiser MichaReiser changed the title [pylint] deprecated dunder methods in Python 3 (PLW3201) [pylint] removed dunder methods in Python 3 (PLW3201) Sep 3, 2024
@MichaReiser MichaReiser self-assigned this Sep 3, 2024
@MichaReiser MichaReiser added preview Related to preview mode features and removed preview Related to preview mode features labels Sep 3, 2024
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@MichaReiser MichaReiser merged commit 9d1bd7a into astral-sh:main Sep 4, 2024
20 checks passed
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.

PLW3201: Customize error message for dunder methods removed with Python 3
5 participants