Let's say there is a very simple class that represents a generic stack and hence is inherited from Generic[T] (§1).
from typing import TypeVar, Generic, List
T = TypeVar('T')
class Stack(Generic[T]): #1
def __init__(self) -> None:
self.items: List[T] = []
def push(self, item: T) -> None:
self.items.append(item)
def pop(self) -> T:
return self.items.pop()
def empty(self) -> bool:
return not self.items
And then let's generate a stub file .pyi for the module in which the Stack class lies, say, stack.py:
$ stubgen stack.py --output stubs
It's obvious that the Generic[T] base class was unexpectedly stripped off (§2). Meanwhile, the type hint for the items property was replaced as Any (§3). Additionally, what makes things more weird is that the stubbed versions of both push and pop still bore the type hint T for the parameter and the return value respectively (§4 and §5).
from typing import Any, TypeVar
T = TypeVar('T')
class Stack: #2
items: Any = ... #3
def __init__(self) -> None: ...
def push(self, item: T) -> None: ... #4
def pop(self) -> T: ... #5
def empty(self) -> bool: ...
What happened during the generation of the stub? Is there any explanation to justify such a behavior?
P.S. My mypy version is 0.790.