Skip to content

[Backport maintenance/2.17.x] Fix check unused arguments false positive bug #8545

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

Merged

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Apr 6, 2023

Backport 156da64 from #8542.

Problem: the special method `__new__` must match the arguments of the
`__init__` method even if `__new__` method does not use them. This
generate `unused-argument` for the `__new__` method.

Fix: the unused arguments check should not be done on the `__new__`
method if the `__init__` method is defined in the same class.

Update `unused-argument` test to include a check for the case of
`__init__` and `__new__` being defined in a class but `__new__` does not
use all of the argument. This is fine because `__new__` must have the
same argument of `__init__`.

Update with a second check in case of `__init__` being not defined in a
class. Then the unused arguments check must be done on `__new__`.

Fixes #3670

(cherry picked from commit 156da64)
@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Apr 6, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.3 milestone Apr 6, 2023
@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Merging #8545 (1dc3174) into maintenance/2.17.x (de0147e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##           maintenance/2.17.x    #8545   +/-   ##
===================================================
  Coverage               95.56%   95.56%           
===================================================
  Files                     178      178           
  Lines                   18786    18794    +8     
===================================================
+ Hits                    17952    17960    +8     
  Misses                    834      834           
Impacted Files Coverage Δ
pylint/checkers/variables.py 97.17% <100.00%> (+0.01%) ⬆️

@Pierre-Sassoulas Pierre-Sassoulas merged commit 84d4959 into maintenance/2.17.x Apr 6, 2023
@Pierre-Sassoulas Pierre-Sassoulas deleted the backport-8542-to-maintenance/2.17.x branch April 6, 2023 17:38
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants