Message398707
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. |
|
Date |
User |
Action |
Args |
2021-08-01 15:19:43 | andrei.avk | set | recipients:
+ andrei.avk, ssbarnea, serhiy.storchaka, Anthony Sottile, gaborjbernat |
2021-08-01 15:19:43 | andrei.avk | set | messageid: <1627831183.44.0.38609783814.issue41973@roundup.psfhosted.org> |
2021-08-01 15:19:43 | andrei.avk | link | issue41973 messages |
2021-08-01 15:19:43 | andrei.avk | create | |
|