Closed
Description
Issue
In my arbitrary sample of three .py
files in the code base, Two files had multiple class methods in which the cls
attribute was never used. It's entirely incomprehensible to me why these are specifically decorated as class methods since they don't access the class. It would improve code readability if they were static methods. Technically, most of them could also be module-level functions but refactoring that appears to be way more effort.
An example is pandas/plotting/matplotlib/core.py
.
Proposed fix
- To prevent anyone from making this mistake again, we should make sure our Linter rejects methods with unused arguments such as PyLint does.
- Write a script that converts all methods (including class methods) with an unused first argument (typically
self
andcls
) to static methods. Run that script across the Pandas codebase. - Fix any resulting test failures or other issues. Though very likely there will be none because a static method is virtually indistinguishable from a class method or instance method except if you check the type directly.
- Make the pull request.