I just realized I didn’t have from __future__ import annotations in the module in question, only in the __main__ file. Adding the future import makes mypy happy.
However, if I use foo as a decorator within a class definition, like this
class Baz:
@foo(1, 'a')
def abc(self):
...
mypy will not find errors in the signature of abc (if the signature of Bar.__init__ is something like Bar.__init__(self, func: Callable[[int, int], str])).
I resolved this by adding a dummy base class for Bar
class BarBase:
def __init__(self, func: Callable[[int, int], str]): ...