pytype
pytype copied to clipboard
Generic, ABC / ABCMeta and __getitem__ can't work together
I ran into a problem
from abc import ABC, abstractmethod
from typing import Generic, TypeVar
T = TypeVar('T')
class A(Generic[T], ABC):
@abstractmethod
def __getitem__(self, index: int) -> T:
...
class B(A[T]):
pass
$ python3 --version
Python 3.6.8
$ pytype --version
2020.03.19
$ pytype test.py 1
Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `/home/[===]/.pytype_output'
[1/1] check test
FAILED: /home/[===]/.pytype_output/pyi/test.pyi
/usr/bin/python3 -m pytype.single --disable pyi-error --imports_info /home/[===]/.pytype_output/imports/test.imports --module-name test -V 3.6 -o /home/[===]/.pytype_output/pyi/test.pyi --analyze-annotated --nofail --quick /home/[===]/test.py
File "/home/[===]/test.py", line 15, in <module>: Invalid TypeVar: cannot pass a TypeVar to a function [invalid-typevar]
File "/home/[===]/test.py", line 15, in <module>: Missing parameter 'index' in call to function A.__getitem__ [missing-parameter]
Expected: (self, index)
Actually passed: (self)
For more details, see https://google.github.io/pytype/errors.html.
ninja: build stopped: cannot make progress due to previous errors.
Seems Generic, ABC / ABCMeta and __getitem__ can't work together
If I remove any one of them, the problem will disappear
Looks like if there is a customized metaclass for class A, it won't be treated as Generic?
Thanks for the report!