(This might be a part of #2416, but I already have those changes)
Pylint reports unsubscriptable-object for _abstract_ generic types:
Run pylint on following file:
from typing import TypeVar, Generic
from abc import ABCMeta, abstractmethod
T = TypeVar('T')
class Factory(Generic[T], metaclass=ABCMeta):
@abstractmethod
def build(self) -> T:
pass
class IntFactory(Factory[int]): # Sadpanda unsubscriptable-object
def build(self) -> int:
return 3
factory = IntFactory()
x: int = factory.build()
Pylint reports E1136: Value 'Factory' is unsubscriptable (unsubscriptable-object) on line 11.
As far as I understand, this is supposed to be ok? mypy 0.660 doesn't complain and python 3.7.1 runs the whole thing.
pylint 2.3.1
astroid 2.2.5
Python 3.7.1 (default, Oct 22 2018, 11:21:55)
[GCC 8.2.0]
Thanks @aviv-ebates I can confirm the bug.
I am having a similar issue, was this problem fixed for anyone?
@santanaraphael This is still an issue, no one got to work on it just yet.
Any update on this ?
Having the same problem.
+1 pylint 2.5.0, astroid 2.4.0, python 3.7.6
I think this doesn't have to do with abstract generic types. I can reproduce this error with just a metaclass:
import typing
variable = typing.TypeVar("variable")
class A(typing.Generic[variable], metaclass=type):
pass
class B(A[variable]):
pass
This might have to do with the fact that typing.Generic[variable].__class__ is typing._GenericAlias, not type, but I couldn't figure out where to go from there.
+1. Cheers.
Not sure if this is related, but it also does not seem to accept the builtin value type as being subscriptable.
Most helpful comment
Thanks @aviv-ebates I can confirm the bug.