Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unsubscriptable-object error reported for abstract generic types #2822

Closed
aviv-ebates opened this issue Mar 20, 2019 · 10 comments · Fixed by #4334
Closed

unsubscriptable-object error reported for abstract generic types #2822

aviv-ebates opened this issue Mar 20, 2019 · 10 comments · Fixed by #4334
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) typing

Comments

@aviv-ebates
Copy link

(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]
@PCManticore
Copy link
Contributor

Thanks @aviv-ebates I can confirm the bug.

@santanaraphael
Copy link

I am having a similar issue, was this problem fixed for anyone?

@PCManticore
Copy link
Contributor

@santanaraphael This is still an issue, no one got to work on it just yet.

@lovasoa
Copy link

lovasoa commented Jan 17, 2020

Any update on this ?

@halvorboe
Copy link

Having the same problem.

@dariobig
Copy link

dariobig commented Apr 30, 2020

+1 pylint 2.5.0, astroid 2.4.0, python 3.7.6

@gibiansky
Copy link

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.

@zuckerruebe
Copy link

+1. Cheers.

pebenito added a commit to pebenito/setools that referenced this issue Oct 17, 2020
Includes some minor code changes to fix errors from static type checking.

Disable unsubscriptable-object pylint check on Wrapper subclass
declarations, as this hits the bug described in pylint-dev/pylint#2822.

Signed-off-by: Chris PeBenito <[email protected]>
@ShadowLNC
Copy link

Not sure if this is related, but it also does not seem to accept the builtin value type as being subscriptable.

@cdce8p
Copy link
Member

cdce8p commented Apr 10, 2021

This issue will be fixed with the next release of pylint.

@cdce8p cdce8p added Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) typing labels Apr 10, 2021
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Apr 12, 2021
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Apr 12, 2021
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Apr 12, 2021
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Apr 13, 2021
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Apr 13, 2021
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Apr 13, 2021
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
halstead pushed a commit to openembedded/meta-openembedded that referenced this issue Apr 13, 2021
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
halstead pushed a commit to openembedded/meta-openembedded that referenced this issue Apr 20, 2021
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
(cherry picked from commit b06d10f)
Signed-off-by: Armin Kuster <[email protected]>
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
What's New in astroid 2.5.3?
============================
Release Date: 2021-04-10

* Takes into account the fact that subscript inferring for a ClassDef may involve __class_getitem__ method

* Reworks the `collections` and `typing` brain so that `pylint`s acceptance tests are fine.

  Closes pylint-dev/pylint#4206

* Use ``inference_tip`` for ``typing.TypedDict`` brain.

* Fix mro for classes that inherit from typing.Generic

* Add inference tip for typing.Generic and typing.Annotated with ``__class_getitem__``

  Closes pylint-dev/pylint#2822

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) typing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants