GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Confusing __class__ for instance of non-generic class that subclasses generic class · Issue #129 · python/typing

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Confusing __class__ for instance of non-generic class that subclasses generic class#129
Copy link
Milestone
3.5.2

Description

@JukkaL
JukkaL
opened on May 21, 2015
Issue body actions

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

Activity

  1. 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[/+] on May 21, 2015
  2. gvanrossum
    added
    bug
    on May 21, 2015
  3. gvanrossum
    self-assigned this
    on May 21, 2015
  4. gvanrossum commented on May 21, 2015

    @gvanrossum
    gvanrossum
    on May 21, 2015
    Member
    More actions

    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.

  5. benjaminp
    unassigned
    gvanrossum
    on Jan 23, 2016
  6. gvanrossum
    added this to the 3.5.2 milestone on Apr 4, 2016
  7. gvanrossum commented on Apr 4, 2016

    @gvanrossum
    gvanrossum
    on Apr 4, 2016
    Member
    More actions

    OK, fixed by #195.

  8. gvanrossum
    closed this as completedon Apr 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      • 3.5.2

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.