False positive on overloaded methods

With SonarCloud we are receiving false positive on overloaded typed methods:

from typing import Literal, overload, Union

class Foo:

    def __init__(self):
        self.var = 2

    def get(self, name: str, *, raw: Literal[False] = False) -> dict[str, Any]:

    def get(self, name: str, *, raw: Literal[True]) -> Union[str, bytes]:

    def get(self, name: str, *, raw: bool) -> Union[dict[str, Any], str, bytes]:

    def get(self, name: str, *, raw: bool = False) -> Union[dict[str, Any], str, bytes]:
        """Do whatever."""
        if raw:
            return name
        return self.var * name

All the methods annotated with @overload with only ... for the implementation should not be getting flagged by python:S2325.

See official docs:

Hello @sodul,

Thanks for reporting this false positive. I created SONARPY-859 to track it.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.