Closed
Description
from typing import Type, TypeVar
T = TypeVar("T", bound="Base")
class Base(object):
pass
class Subclass(Base):
pass
def create_instance(instance_type: Type[T] = Base) -> T:
return instance_type()
Mypy (0.641) fails with:
Incompatible default for argument "instance_type" (default has type "Type[Base]", argument has type "Type[T]")
Revealed types of return values:
create_instance() # <nothing>, but I would expect Base*
create_instance(Base) # Base*, OK
create_instance(Subclass) # Subclass*, OK
Metadata
Metadata
Assignees
Labels
No labels