Skip to content

gh-149574: Document that is_typeddict, is_protocol, is_dataclass, isclass return False for generic aliases#149604

Open
JelleZijlstra wants to merge 2 commits intopython:mainfrom
JelleZijlstra:istypeddictdoc
Open

gh-149574: Document that is_typeddict, is_protocol, is_dataclass, isclass return False for generic aliases#149604
JelleZijlstra wants to merge 2 commits intopython:mainfrom
JelleZijlstra:istypeddictdoc

Conversation

@JelleZijlstra
Copy link
Copy Markdown
Member

@JelleZijlstra JelleZijlstra commented May 9, 2026

Comment thread Doc/library/inspect.rst Outdated
Return ``True`` if the object is a class, whether built-in or created in Python
code.

This function returns ``False`` for :ref:`generic specializations <types-generic-aliases>` of classes,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(.venv) ~/Desktop/cpython  issue-149600 ✔                                                 
» ag 'generic specializations' Doc/
                                                                                           
(.venv) ~/Desktop/cpython  issue-149600 ✔                                              1 ⚠️
» 

this term is never used in our docs as of right now, maybe we should call it "generic aliases"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike the term "generic alias" because generic aliases are neither generic nor aliases. But I guess it's the established term.

Copy link
Copy Markdown
Member

@picnixz picnixz May 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In typing.rst we say:

Generic aliases can be instantiated or subclassed, similar to real classes, but the
above examples illustrate that type variables are erased at runtime. Generic Stack
instances are just ordinary Python objects, and they have no extra runtime overhead or
magic due to being generic, other than overloading the indexing operation.

and this referrs to Stack[int] for instance to indicate that Stack[int]() is possible. So AFAICT, "generic aliases" refer to specializations. I also use the term "specialization" because that's what we do in C++ for templates, so formally I would agree with Jelle (I wished we could also be a bit more formal in general in the docs but I guess we would need to go through both the typing specs and the docs to change all of that; it could be confusing for others, especially when type(list[int]) returns GenericAlias...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also use the term "specialization" because that's what we do in C++ for templates

I've never used C++ and this is the first time I hear this term :)

Comment thread Doc/library/typing.rst
Comment thread Doc/library/typing.rst
@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32616918 | 📁 Comparing 0ab6000 against main (7241f27)

  🔍 Preview build  

4 files changed
± library/dataclasses.html
± library/inspect.html
± library/stdtypes.html
± library/typing.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants