I simplified the code just for proof of concept:
class Hypothesis(NamedTuple):
logprob: float
def attach(self) -> Hypothesis:
return Hypothesis(logprob=4)
While mypy doesn't complain at this, the python interpreter crashes with a NameError saying:
Traceback (most recent call last):
File "./decode.py", line 31, in <module>
class Hypothesis(NamedTuple):
File "./decode.py", line 34, in Hypothesis
def attach(self) -> Hypothesis:
NameError: name 'Hypothesis' is not defined
Unfortunately, I dropped the return type annotation as a result (which mypy didn't complain about) in order to make it runnable.