False positive when subclassing

We have noticed that python:S117 will flag bad argument names for the argument names, even though the names have to be consistent with the super class definitions.

This is same code that subclasses json.JSONEncoder from the standard library where the argument is named o, giving it a “proper” name would actually be a bad thing since it would no longer mirror the implementation of the json.JSONEncoder class.

from __future__ import annotations

import json

from typing import Any, Final, Iterable, Sequence


class CustomJSONEncoder(json.JSONEncoder):
    """Custom JsonEncoder."""
    def default(self, o: Any) -> dict[str, Any]:
        ...

Hello @sodul ,

Thanks for the reporting.
We have reproduced the issue and created the SONARPY-1845 ticket to fix it.

Have a nice day,
Maksim Grebeniuk

1 Like