a type warning started popping up today in some of my code after I upgraded the version of mypy that I was using. There doesnt seem to be too much literature on the subject, so hoping someone here can help me out!
I have a MetaClass defined like the following...
from __future__ import annotations
class MyMetaClass(type):
def __new__(mcs,
name: str,
bases: Tuple[type, ...],
namespace: Dict[str, Any],
) -> MyMetaClass:
# Custom code... doesnt matter
# ...
# ...
return type.__new__(mcs, name, bases, namespace)
Today, mypy started spitting out the following error...
error: Incompatible return value type (got "type", expected "MyMetaClass")
Ive tried the following iterations of the return statement, all with no success...
return super().__new__(mcs, name, bases, namespace)
return super(MyMetaClass, mcs).__new__(mcs, name, bases, namespace)
Any suggestions on how to get around this warning? I ended up settling for a cast... but it feels like there has to be something better.
return cast(MyMetaClass, super().__new__(mcs, name, bases, namespace))