Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[pylint] - implement super-without-brackets/W0245 #9257

Merged
merged 5 commits into from
Jan 2, 2024

Conversation

diceroll123
Copy link
Contributor

Summary

Implement super-without-brackets/W0245

See: #970

Test Plan

cargo test

Copy link
Contributor

github-actions bot commented Dec 23, 2023

ruff-ecosystem results

Linter (stable)

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

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

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

+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
... 74 additional changes omitted for project

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

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

+ src/bokeh/application/application.py:42:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/application.py:42:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/application.py:43:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/application.py:43:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/application.py:44:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/application.py:44:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/application.py:50:5: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/application.py:50:5: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/code.py:45:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code.py:45:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/code.py:46:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code.py:46:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/code.py:47:1: TID252 Prefer absolute imports over relative imports from parent modules
+ src/bokeh/application/handlers/code.py:47:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code.py:47:1: TID252 Relative imports from parent modules are banned
- src/bokeh/application/handlers/code.py:47:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/code_runner.py:33:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code_runner.py:33:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/code_runner.py:34:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code_runner.py:34:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/directory.py:65:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/directory.py:65:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/directory.py:66:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/directory.py:66:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/directory.py:67:1: TID252 Prefer absolute imports over relative imports from parent modules
+ src/bokeh/application/handlers/directory.py:67:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/directory.py:67:1: TID252 Relative imports from parent modules are banned
- src/bokeh/application/handlers/directory.py:67:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/directory.py:78:5: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/directory.py:78:5: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/document_lifecycle.py:25:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/document_lifecycle.py:25:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/function.py:44:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/function.py:44:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/function.py:45:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/function.py:45:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/handler.py:52:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/handler.py:52:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/handler.py:53:1: TID252 Prefer absolute imports over relative imports from parent modules
+ src/bokeh/application/handlers/handler.py:53:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/handler.py:53:1: TID252 Relative imports from parent modules are banned
- src/bokeh/application/handlers/handler.py:53:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/lifecycle.py:28:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/lifecycle.py:28:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/lifecycle.py:29:1: TID252 Prefer absolute imports over relative imports from parent modules
+ src/bokeh/application/handlers/lifecycle.py:29:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/lifecycle.py:29:1: TID252 Relative imports from parent modules are banned
- src/bokeh/application/handlers/lifecycle.py:29:1: TID252 Relative imports from parent modules are banned
... 3174 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
TID252 3306 1653 1653 0 0

Linter (preview)

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

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

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

+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
+ tests/providers/amazon/aws/hooks/test_eks.py:57:1: TID252 Prefer absolute imports over relative imports from parent modules
... 74 additional changes omitted for project

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

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

+ src/bokeh/application/handlers/code.py:45:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code.py:45:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/code.py:46:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code.py:46:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/code.py:47:1: TID252 Prefer absolute imports over relative imports from parent modules
+ src/bokeh/application/handlers/code.py:47:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code.py:47:1: TID252 Relative imports from parent modules are banned
- src/bokeh/application/handlers/code.py:47:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/code_runner.py:33:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code_runner.py:33:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/code_runner.py:34:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/code_runner.py:34:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/directory.py:65:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/directory.py:65:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/directory.py:66:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/directory.py:66:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/directory.py:67:1: TID252 Prefer absolute imports over relative imports from parent modules
+ src/bokeh/application/handlers/directory.py:67:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/directory.py:67:1: TID252 Relative imports from parent modules are banned
- src/bokeh/application/handlers/directory.py:67:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/directory.py:78:5: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/directory.py:78:5: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/document_lifecycle.py:25:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/document_lifecycle.py:25:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/function.py:44:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/function.py:44:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/function.py:45:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/function.py:45:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/handler.py:52:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/handler.py:52:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/handler.py:53:1: TID252 Prefer absolute imports over relative imports from parent modules
+ src/bokeh/application/handlers/handler.py:53:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/handler.py:53:1: TID252 Relative imports from parent modules are banned
- src/bokeh/application/handlers/handler.py:53:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/lifecycle.py:28:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/lifecycle.py:28:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/lifecycle.py:29:1: TID252 Prefer absolute imports over relative imports from parent modules
+ src/bokeh/application/handlers/lifecycle.py:29:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/lifecycle.py:29:1: TID252 Relative imports from parent modules are banned
- src/bokeh/application/handlers/lifecycle.py:29:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/notebook.py:36:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/notebook.py:36:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/notebook.py:37:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/notebook.py:37:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/script.py:52:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/script.py:52:1: TID252 Relative imports from parent modules are banned
+ src/bokeh/application/handlers/server_lifecycle.py:29:1: TID252 Prefer absolute imports over relative imports from parent modules
- src/bokeh/application/handlers/server_lifecycle.py:29:1: TID252 Relative imports from parent modules are banned
... 3012 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
TID252 3144 1572 1572 0 0

@diceroll123
Copy link
Contributor Author

diceroll123 commented Dec 23, 2023

Is it possible to narrow the guard clauses down more?

I'm unsure what the best way to have the semantic model know if we're within a subclass would be here. Please advise!

pub(crate) fn super_without_brackets(checker: &mut Checker, func: &Expr) {
if !checker.semantic().current_scope().kind.is_function() {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

We could probably check if we're in a function immediately within a class?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, can you try using function_type::classify for this, to detect that we're in a method?

Copy link
Member

Choose a reason for hiding this comment

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

You will need to pass the parent scope via something like:

let Some(parent) = &checker.semantic().first_non_type_parent_scope(scope) else {
    return;
};

Instead of the current scope.

Copy link
Contributor Author

@diceroll123 diceroll123 Dec 23, 2023

Choose a reason for hiding this comment

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

Updated! Seems much better now, LMK!

And thanks!

@charliermarsh charliermarsh added rule Implementing or modifying a lint rule preview Related to preview mode features labels Dec 23, 2023
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 merged commit 3fcc140 into astral-sh:main Jan 2, 2024
15 of 16 checks passed
# for free to join this conversation on GitHub. Already have an account? # 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