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

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

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

    @overload
    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:
https://docs.python.org/3/library/typing.html#typing.overload

Hello @sodul,

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

Cheers,
Guillaume

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