[issue41973] Docs: TypedDict is now of type function instead of class
Andrei Kulakov
report at bugs.python.org
Sun Aug 1 11:19:43 EDT 2021
Andrei Kulakov <andrei.avk at gmail.com> added the comment:
I haven't looked too much into typing module, so take this with a grain of salt, but my understanding is that TypedDict is a special construct (as the first sentence in the docs defines it), which can be used as a base. I think most users would consider something a kind of a class if it can be inherited from by a user-defined class, so this classification in the docs is useful.
Normally functions can't be used as a base of course. There's no "inheritable from" abc or anything like that and functions are not inherited from "function type". You generally don't care if something is a function, you care if it's a callable and test for that with `callable()`.
So in a sense a function is the most inherently duck typed object in Python.
The only way for a specific check of a function type is AFAIK type(known_function) == type(myobj), but this type of checking is discouraged.
So static checkers that run into a problem with this are probably assuming too much about what a function is or should be in Python.
To sum up, TypedDict is a kind of a construct between a class and a function that's more usefully documented as, and used as, a class. The docs make it very clear that it's not your usual, run of the mill class.
----------
nosy: +andrei.avk
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41973>
_______________________________________
More information about the Python-bugs-list
mailing list