from typing import Protocol, Tuple, TypedDict
class Foo(TypedDict):
foo: str
bar: int
baz: Tuple[str, int]
baaz: Tuple[float, ...]
class Functionality(Protocol):
def do(self, it: Foo): ...
class MyFunctionality: # not explicitly implemented
def do(self, it: Foo): ...
class DoIt:
def execute(self, it: Foo, func: Functionality): ...
doit = DoIt().execute({ # Type checks
"foo": "foo",
"bar": 7,
"baz": ("str", 2),
"baaz": (1.0, 2.0)}, MyFunctionality())
Protocols and TypedDicts let you do nice structural stuff, similar typescript (though not as feature complete). Types are good enough on python that I would never consider a project without them, and I work with pandas and numpy a lot. You change your workflow a little bit so that you end up quarantining the code that interfaces with third-party libraries that don't have good type support behind your own functions that do. There are other pretty cool type things as well. Python is definitely in much better shape than it was.Combine all of that with Pyright's ability to do more advanced type inference and its like a whole new language experience.