Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pylint W0622 (Redefining built-in) when overriding "standard" methods in subclasses

In Python, many methods define argument variables with "standardized" names, like:

def __exit__(self, type, value, traceback):

In the line above, variable type causes pylint to warn (W0622) that a built-in is being redefined: Redefining built-in 'type' (redefined-builtin).

There are many ways to fix this and make pylint happy (rename the variable, add a pylint directive (# pylint: disable=W0622) to ignore the problem, etc.).

What is the best/preferred/suggested/conventionally-used way (if any) to maintain a good code quality and make pylint happy in these cases?

like image 978
Starnuto di topo Avatar asked May 09 '19 09:05

Starnuto di topo


1 Answers

It could be considered as a bad practise to disable pylint warning.

Quoting quantifiedcode.com :

In order for __exit__ to work properly it must have exactly three arguments: exception_type, exception_value, and traceback. The formal argument names in the method definition do not need to correspond directly to these names, but they must appear in this order.

As such a good option could be to use tuple packing def __exit__(self, *exc)

This what is suggested in this official documentation: https://docs.python.org/3/library/contextlib.html

like image 67
scoulomb Avatar answered Oct 13 '22 00:10

scoulomb