Replies: 1 comment 2 replies
-
Thanks so much for the awesome question, @k4ml. You're absolutely right, of course. @beartype currently lacks support for PEP 526 (AKA, variable annotations). We're tracking @beartype support for PEP 526 at long-standing feature request #105. I've been debating whether to tackle #105 now or later. This seems to be much more popular than I'd thought. I'm edging towards: "Now! Gods! Oh, Gods above! Do this!" Until I do something, there is a temporary solution. I almost regret mentioning this, because this requires manual boilerplate. But... @beartype's shiny DOOR API does provide an out-of-the-box solution for manually type-checking anything at any time: the from beartype import beartype
from beartype.door import die_if_unbearable
class TP: pass
@beartype
def add(x: int, y: int) -> TP:
return TP()
@beartype
def main():
total: str = add(1, 2)
die_if_unbearable(total, str) # <-- this is the magic. but... it's not so magical.
main() @beartype now raises the expected exception:
I know. I know. Having to manually call |
Beta Was this translation helpful? Give feedback.
-
This will give errors when running with mypy:-
But beartype doesn't throw any error when actually running it.
Beta Was this translation helpful? Give feedback.
All reactions