Mypy: Overloading staticmethods

Created on 23 Oct 2019  路  2Comments  路  Source: python/mypy

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

bug priority-1-normal

Most helpful comment

@Michael0x2a Any chance you are excited to take another look at this thrilling interaction?

All 2 comments

It looks like it only works right now if you call it directly via the class: Snafu.snauf('123').

@Michael0x2a Any chance you are excited to take another look at this thrilling interaction?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

snakescott picture snakescott  路  27Comments

JukkaL picture JukkaL  路  27Comments

mr-rodgers picture mr-rodgers  路  29Comments

timabbott picture timabbott  路  28Comments

msullivan picture msullivan  路  26Comments