You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
error: Return type of <functionName> incompatible with supertype <ClassName> #3576
from typing import NamedTuple, Dict, Optional, List, Any
class Object1(object, metaclass=ABCMeta):
def __init__(self) -> None:
pass
@abstractmethod
def get_logo(self) -> Optional[str]:
pass
class Object2(Object1):
def __init__(self) -> None:
super().__init__()
async def get_logo(self) -> Optional[str]:
return ''
class Object3(Object1):
def __init__(self) -> None:
super().__init__()
async def get_logo(self) -> Optional[str]:
return None
And the mypy alerts me that:
test.py:19: error: Return type of "get_logo" incompatible with supertype "Object1"
test.py:27: error: Return type of "get_logo" incompatible with supertype "Object1"
But it's look OK to me, because they return the same type...
I run it with: mypy --strict-optional --ignore-missing-imports <file>
Great! It's corrects my errors, but let me get that straight- what is the difference in the type annotations between async def and def? Should I wrote something differently? Maybe use the typing.Coroutine as the returned type from the async defs?
Mypy internally uses typing.Awaitable[x] as the return type for async def, but this wrapping happens automatically so your signatures are fine. You can use reveal_type(obj.method) to display the signature of a method as mypy sees it.
Activity
JukkaL commentedon Jun 20, 2017
Objectdoesn't useasync defbut subclasses use it, so the actual return types are different, though the annotations look the same.YuvalPruss commentedon Jun 20, 2017
Great! It's corrects my errors, but let me get that straight- what is the difference in the type annotations between
async defanddef? Should I wrote something differently? Maybe use thetyping.Coroutineas the returned type from theasync defs?JukkaL commentedon Jun 20, 2017
Mypy internally uses
typing.Awaitable[x]as the return type forasync def, but this wrapping happens automatically so your signatures are fine. You can usereveal_type(obj.method)to display the signature of a method as mypy sees it.