Re:TypeScript Is Surprisingly OK for Compilers
by nerdponx on Friday August 18, 2023 @03:06PM
(#37180563)
The typical approach to this in Python is to define a callable class instead. If you define the __call__() method on a class, instances of the class will be callable.
As mentioned in the sibling comment, you can define a Protocol which is analogous to an interface, so if you had a protocol like this:
Then IntAdder would be considered a subclass of ValueUpdater[int] by the type checker. Demo: https://mypy-play.net/?mypy=1.5.1&python=3.11&flags=strict&g...
[ Parent
| on HN ]
There are no comments on this comment yet.