Replies: 1 comment
-
Resolved by 22787fb. The
$ pwd
/home/leycec/tmp/pogo
$ ls
src/
$ ls src/
script.py helper.py
$ python src/script.py
Traceback (most recent call last):
File "/home/leycec/tmp/pogo/src/script.py", line 32, in <module>
beartype_this_package()
File "/home/leycec/py/beartype/beartype/claw/_clawmain.py", line 302, in beartype_this_package
raise BeartypeClawHookUnpackagedException(exception_message)
beartype.roar.BeartypeClawHookUnpackagedException: Top-level script
"/home/leycec/tmp/pogok/src/script.py" resides outside package structure.
Consider calling another "beartype.claw" import hook. However, note that only
other modules will be type-checked. "/home/leycec/tmp/pogo/src/script.py" itself
will remain unchecked. All business logic should reside in submodules
subsequently imported by "/home/leycec/tmp/pogo/src/script.py": e.g.,
# Instead of this at the top of "/home/leycec/tmp/pogo/src/script.py"...
from beartype.claw import beartype_this_package # <-- you are here
beartype_this_package() # <-- feels bad
# ...pass the basename of the "src/" subdirectory explicitly.
from beartype.claw import beartype_package # <-- you want to be here
beartype_package("src") # <-- feels good
from src.main_submodule import main_func # <-- still feels good
main_func() # <-- *GOOD*! "beartype.claw" type-checks this
some_global: str = 0xFEEDFACE # <-- *BAD*! "beartype.claw" ignores this
This has been a message from your friendly neighbourhood bear. Thanks so much for pointing out that none of this made any sense whatsoever. See also issue #320 for an excruciating discussion that could melt your brain. When that happens, it's not my fault. 🧠 🔥 |
Beta Was this translation helpful? Give feedback.
-
(Note: just made these examples from latest 0.17.2 beartype)
I feel like I'm messing this up, but I've been falling back on the beartype decorator because the way which my projects use python, are mostly as scripts, or helper classes / files / pkgs for scripts.
Examples: (I did back-annotate the running results, details below files)
What I hope to accomplish: running any of the main*.py scripts throws a beartype exception.
For example, this is the only one which seems to do what I want:
The following... reveal that I don't know what I'm doing.
How does the new claw get properly used for scripts? There's so many juicy beartype checks that don't get called, like variable assignment, when I only bearly decorate my functions.
Beta Was this translation helpful? Give feedback.
All reactions