You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm defining a small hierarchy of database adapters for MySQL and PostgreSQL. There's a base class that defines some common methods, and there's one subclass for each of MySQL and PostgreSQL. Each of these subclasses happen to override a particular method of the base class merely for the purpose of changing the docstring to explain what this method does in a MySQL vs. a PostgreSQL context, but the implementation doesn't change because the base class method delegates to private methods defined by the subclasses. Explaining the reasons for this design is outside the scope of this ticket, but please trust that there are good reasons.
classDatabaseAdapter(ABC):
...
@abstractmethoddef_getvar(self, name: str) ->Any:
...
defgetvar(self, name: str) ->Any:
"""Get the value of the given database variable."""returnself._getvar(name)
classMySQLAdapter(DatabaseAdapter):
...
def_getvar(self, name: str) ->Any:
# Do the MySQL thing.
...
defgetvar(self, name: str) ->Any:
""" Get the value of the given database session variable. This is equivalent to `SELECT @@name`. """returnsuper().getvar(name)
classPostgreSQLAdapter(DatabaseAdapter):
...
def_getvar(self, name: str) ->Any:
# Do the PostgreSQL thing.
...
defgetvar(self, name: str) ->Any:
""" Get the value of the given database run-time parameter. This is equivalent to `SHOW name`. """returnsuper().getvar(name)
See how each class's getvar docstring differs? I want to maintain this difference in docstrings without changing the delegation behavior of the method.
However, this code makes pylint complain with a useless-super-delegation warning. I would argue that pylint should probably detect the subclass methods' different docstrings and take that as a sign that this is being done to override the base class method's docstring and not log a useless-super-delegation. Is there any way other than # pylint: disable=useless-super-delegation to resolve this?
The text was updated successfully, but these errors were encountered:
@jmehnle sorry for the delay. I do not think there is other way that disabling the useless-super-delegation message.
Maybe @Pierre-Sassoulas or @cdce8p will have better idea?
If we let the docstrings being a little different not raise any message for this, then it will be considered a false negative when a bad copy paste is not detected. I think this is somewhat similar to #3536, we could maybe add a "super-delegation-only-redefine-docstring" message that can then be disabled project wide.
I tend to agree with @Pierre-Sassoulas here. pylint should focus on the code itself. It's too easy for docstrings to become outdated. Where I disagree is if it's really necessary to add a new option for it that subsequently needs to be maintained.
If it was my code, I would probably do # pylint: disable=useless-super-delegation ones at the beginning of the file and forget about it.
I'm defining a small hierarchy of database adapters for MySQL and PostgreSQL. There's a base class that defines some common methods, and there's one subclass for each of MySQL and PostgreSQL. Each of these subclasses happen to override a particular method of the base class merely for the purpose of changing the docstring to explain what this method does in a MySQL vs. a PostgreSQL context, but the implementation doesn't change because the base class method delegates to private methods defined by the subclasses. Explaining the reasons for this design is outside the scope of this ticket, but please trust that there are good reasons.
See how each class's
getvar
docstring differs? I want to maintain this difference in docstrings without changing the delegation behavior of the method.However, this code makes
pylint
complain with auseless-super-delegation
warning. I would argue thatpylint
should probably detect the subclass methods' different docstrings and take that as a sign that this is being done to override the base class method's docstring and not log auseless-super-delegation
. Is there any way other than# pylint: disable=useless-super-delegation
to resolve this?The text was updated successfully, but these errors were encountered: