-
Shouldn't the following raise an error?
When executing the program, it runs without errors. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Excellent question! The tl;dr (i.e., short answer) is that you probably want to do this instead: # In the "{your_package}.__init__" submodule:
from beartype.claw import beartype_this_package
beartype_this_package() And then... # In the "{your_package}.__main__" submodule (or whatevahs):
from typing import Annotated
from annotated_types import Gt
from beartype.vale import Is
def main():
foo: list[Annotated[int, Is[Gt(0)]]] = [-1, 0, 10]
print(foo)
main() You should now receive joy. You may also be thinking to yourself:
Boring Stuff Follows: It Is BoringAllow me to now boringly explicate.
From the perspective of from beartype import beartype
@beartype
def main():
foo = [-1, 0, 10]
print(foo)
main() Note the complete absence of type hints. Blame CPython. I always do. You may now be thinking to yourself:
More Boring Stuff: Boring Stuff Intensifies
tl;dr: That Was Sure BoringAlways As these sorts of issues continue to arise and bedevil us, we might even officially deprecate the |
Beta Was this translation helpful? Give feedback.
-
Excellent question! I'm... unsure, actually. Your exception traceback is missing the actual exception message. It's unclear what's going on there, really. That said, if @beartype does not already support the third-party Likewise, beartype should probably also provide equivalent Potential new beartype validators include:
There are heaps more, too. But those above would be a great start. Deep thoughts for Christmas time. ☃️ ❄️ |
Beta Was this translation helpful? Give feedback.
-
Ah... ha. Thanks so much for that full traceback. Looks like Thankfully, you don't even need from typing import Annotated
from beartype.vale import Is
def main():
foo: list[Annotated[int, Is[lambda number: number > 0]]] = [-1, 0, 10] # <-- srsly. that's it.
print(foo)
main() Srsly. That's it. Do Really! Believe my lies. 😉 |
Beta Was this translation helpful? Give feedback.
Excellent question! The tl;dr (i.e., short answer) is that you probably want to do this instead:
And then...
You should now receive joy. You may also be thinking to yourself:
Boring Stuff Follows: It Is Boring
Allow me to now boringly explicate.
foo: list[Annotated[int, Is[Gt(0)]]]…