I have encountered the typing module's callable type in a Python book, and saw it tangentially referenced in a couple of videos, but I still don't really grasp what it is for, when to choose to use it, and how it works. (The O'Reilly text I am mostly using is more of a desktop reference than a textbook.)
Hoping someone here might have a suggestion for a good YouTube explanation/demonstration.
1 Comments
jim@programming.dev · 9 pts · 3y
The first way to use it is with any type annotation: you just use it for documentation.
These type annotations can help document and make editors parse your code to make suggestions/auto-complete work better.
The second way to use it is by creating a callable. A callable is an abstract base class that requires you to implement the
__call__method. Your new callable can be called like any function.