Skip to content

Document that inspect.isclass returns False for GenericAlias instances #132467

@RobertoPrevato

Description

@RobertoPrevato

Bug report

Bug description:

Hi
I am not sure if this is a bug, but I use the bug template because I couldn't find a better one to submit questions like this one.

The documentation says, "User-defined generic classes can be instantiated.".

import inspect
from typing import TypeVar, Generic

T = TypeVar("T")


class Node(Generic[T]):
    x: T  # Instance attribute (see below)

    def __init__(self, label: T | None = None) -> None:
        self.label = label


x = Node("")  # Inferred type is Node[str]
y = Node(0)  # Inferred type is Node[int]
z = Node()  # Inferred type is Node[Any]


# Also OK:
y = Node[int](0)


print(inspect.isclass(Node))  # True
print(inspect.isclass(Node[int]))  # False  (shouldn't this be True?)
print(inspect.isclass(Node[str]))  # False  (shouldn't this be True?)

In the example above, shouldn't calls such as inspect.isclass(Node[int]) return True, since they can be instantiated and used like normal classes?

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Labels

docsDocumentation in the Doc direasy

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy