Document that `inspect.isclass` returns False for `GenericAlias` instances
Aperta
@AbduazizZiyodov ci sta già lavorando.
Dal 13/4/2025.
docs
easy
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
- gh-133504
- gh-150854
- gh-151116
- gh-151117
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.