When working on #91, Rares Vernica and I ran into a situation where we were getting a None produced in what we thought was a Delayed[Drop]. It turned out that the culprit was StaticOperation.schedule(), which was defined as
The problem was that delayed() returns the result of the function wrapped in a future, so for this to be a Delayed[V], cb() would have to return a V, but it didn't. But since there were no type hints at all on cb(), MyPy ignored it and figured we knew what we were doing.
We didn't.
As soon as we added a type hint, it complained, and we realized that what we needed was
When working on #91, Rares Vernica and I ran into a situation where we were getting a
None
produced in what we thought was aDelayed[Drop]
. It turned out that the culprit wasStaticOperation.schedule()
, which was defined asThe problem was that
delayed()
returns the result of the function wrapped in a future, so for this to be aDelayed[V]
,cb()
would have to return aV
, but it didn't. But since there were no type hints at all oncb()
, MyPy ignored it and figured we knew what we were doing.We didn't.
As soon as we added a type hint, it complained, and we realized that what we needed was
which, incidentally, was the pattern that had already been used for
Operation.schedule_for()
.Doing a grep, there appear to be a number of other functions without return types, some with no type hints at all.
Looking at the MyPy docs, there are a couple of flags we should give to MyPy to help us find them:
--disallow-untyped-defs
reports an error whenever it encounters a function definition without type annotations.--disallow-incomplete-defs
reports an error whenever it encounters a partly annotated function definition.Migrated from internal repository. Originally created by @EvanKirshenbaum on Sep 14, 2022 at 4:23 PM PDT. Closed on Sep 28, 2022 at 10:30 AM PDT.