Skip to content

Confusing __class__ for instance of non-generic class that subclasses generic class #129

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

Closed
JukkaL opened this issue May 21, 2015 · 2 comments
Milestone

Comments

@JukkaL
Copy link
Contributor

JukkaL commented May 21, 2015

The following program prints __main__.A[int] even though A is not generic. I'd expect it to print something like <class '__main__.A'>.

from typing import Iterator

class A(Iterator[int]):
    def __next__(self): pass

print(A().__class__)

Also, this does not generate an exception, even though A is not generic:

def f(x: A[int]) -> None: pass
@JukkaL JukkaL changed the title Confusing __class__ for instance of non-generic class that subclasses generic clsas Confusing __class__ for instance of non-generic class that subclasses generic class May 21, 2015
@gvanrossum gvanrossum added the bug label May 21, 2015
@gvanrossum gvanrossum self-assigned this May 21, 2015
@gvanrossum
Copy link
Member

I'm on the fence about calling this a bug. What I implemented in rev 25af77d is that no matter how you instantiate A, you always get the original class A as the instance's __class__. And that is what's happening here. It just so happens that the actual class A remembers its parameters. Regarding using A[int] later, that probably shouldn't be allowed -- I need to rework the logic here. This is also related to issue #115. I will have to come back to this later.

@gvanrossum
Copy link
Member

OK, fixed by #195.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants