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

Generic class is unsubscriptable #3520

Closed
Foobin opened this issue Apr 26, 2020 · 4 comments
Closed

Generic class is unsubscriptable #3520

Foobin opened this issue Apr 26, 2020 · 4 comments

Comments

@Foobin
Copy link

Foobin commented Apr 26, 2020

This issue is almost identical to #2416. The difference between my issue and #2416 is where the error occurs.

Steps to reproduce

I have the following class

T = TypeVar('T', bound=Component)

class MyClass(Component, Generic[T]): # in #2416 the unsubscriptable error occurs here
    pass

The above has no pylint errors, as expected. However, I am unable to create instances of MyClass, or inherit from MyClass without an unsubscriptable error popping up in the editor. The code itself runs fine:

class Foo(Component):
    pass

instance = MyClass[Foo]()  # -> Value 'MyClass' is unsubscriptable

class InheritMyClass(MyClass[Foo]): # -> Value 'MyClass' is unsubscriptable
    pass

Current behavior

Value 'MyClass' is unsubscriptable --- pylint(unsubscriptable-object)

pylint --version output

I am using the pylint bundled with the newest version (2020.4.74986 (20 April 2020)) of Microsoft's Python extension for vscode,

@PCManticore
Copy link
Contributor

Thanks for the report.

@mostrows2
Copy link

mostrows2 commented Jun 12, 2020

Here's another snippet that produces the error. Note that removing abc.ABC makes the error go away.

import abc
from typing import TypeVar, Generic, Protocol

class Instance:
    def method(self) -> str:
        return "foo"

class BoundObj(Protocol):
    def method(self) -> str:
        ...

T = TypeVar('T', bound=BoundObj)

class Base(abc.ABC, Generic[T]):
    T: BoundObj

class X(Base[Instance]):
    pass

@carstencodes
Copy link

The error is also removed, if abc.ABC and Generic[T] are swapped.

@cdce8p
Copy link
Member

cdce8p commented Oct 17, 2021

@Foobin and @mostrows2 I wasn't able to reproduce either of bug descriptions with the latest pylint version. We improved the handling of typing.Generic in recent versions, so I would assume that the issues have been fixed already. Going to close this issue.

If you still encounter them, please report back and I'll reopen it.

@cdce8p cdce8p closed this as completed Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants