Pylint: unsubscriptable-object error reported for abstract generic types

Created on 20 Mar 2019  路  9Comments  路  Source: PyCQA/pylint

(This might be a part of #2416, but I already have those changes)
Pylint reports unsubscriptable-object for _abstract_ generic types:

Steps to reproduce

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()

Current behavior

Pylint reports E1136: Value 'Factory' is unsubscriptable (unsubscriptable-object) on line 11.

Expected behavior

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 --version output

pylint 2.3.1
astroid 2.2.5
Python 3.7.1 (default, Oct 22 2018, 11:21:55)
[GCC 8.2.0]
bug

Most helpful comment

Thanks @aviv-ebates I can confirm the bug.

All 9 comments

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.

Was this page helpful?
0 / 5 - 0 ratings