Skip to content

Overloading staticmethods #7781

Closed
@nautics889

Description

@nautics889

Overloaded staticmethod isn't considered correctly by the type checker.
foobar.py

from typing import overload

class Snafu(object):
    @overload
    @staticmethod
    def snafu(value: None) -> None: ...

    @overload
    @staticmethod
    def snafu(value: bytes) -> bytes: ...

    @overload
    @staticmethod
    def snafu(value: str) -> bytes: ...

    @staticmethod
    def snafu(value):
        return bytes(value, encoding='UTF-16')

print(Snafu().snafu('123'))

While running mypy foobar.py expected output: Success: no issues found in 1 source file,
but got foobar.py:21: error: No overload variant of "snafu" of "Snafu" matches argument type "str" .
I guessed #5224 had to fix this, but i've got the behavior above.

Am i doing something wrong?

mypy v0.740, Python v3.7.4

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions