gh-149574: Document that is_typeddict, is_protocol, is_dataclass, isclass return False for generic aliases#149604
gh-149574: Document that is_typeddict, is_protocol, is_dataclass, isclass return False for generic aliases#149604JelleZijlstra wants to merge 2 commits intopython:mainfrom
Conversation
…s, isclass return False for generic aliases
| 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, |
There was a problem hiding this comment.
(.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"?
There was a problem hiding this comment.
I dislike the term "generic alias" because generic aliases are neither generic nor aliases. But I guess it's the established term.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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 :)
Documentation build overview
4 files changed± library/dataclasses.html± library/inspect.html± library/stdtypes.html± library/typing.html |
Uh oh!
There was an error while loading. Please reload this page.