-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Generalize beartype.door.{is_bearable,die_if_unbearable}
to dynamically resolve relative forward references, even if doing so is slower than watching paint dry 😄
#364
Comments
Totally right, @uriyasama. That said:
Really? Wild. The In any case, this is terribad! I've been meaning to generalize these functions to support relative forward references for a few years now – but nobody ever complained. So, I did nothing instead. Also...
Excellent suggestion! Thankfully, @beartype can do much better than that. By the non-portable black magic of call stack introspection, @beartype can dynamically crawl up the call stack until it finds the class referenced by each relative forward reference. This isn't so much hard as it sloooooooooow. But code that works slowly beats code that doesn't work at all. 🥲 Thanks for complaining. Without complaints, I just play video games. That's bad for @beartype and it's bad for your codebase. |
beartype.door.{is_bearable,die_if_unbearable}
to dynamically resolve relative forward references
beartype.door.{is_bearable,die_if_unbearable}
to dynamically resolve relative forward referencesbeartype.door.{is_bearable,die_if_unbearable}
to dynamically resolve relative forward references, even if doing so is slower than watching paint dry
beartype.door.{is_bearable,die_if_unbearable}
to dynamically resolve relative forward references, even if doing so is slower than watching paint drybeartype.door.{is_bearable,die_if_unbearable}
to dynamically resolve relative forward references, even if doing so is slower than watching paint dry 😄
@leycec Perfect! Yeah your idea sound pretty resilient, and slower than honey. Regarding this issue appearing only following 0.18.0, this is because starting that version you are deep checking dictionaries. |
Starting with the latest beartype version I started getting this error:
beartype.roar.BeartypeDecorHintForwardRefException: Die_if_unbearable() type hint typing.Dict[str, ForwardRef('XXXX')] type hint relative forward reference "XXXX" currently only type-checkable in type hints annotating @beartype-decorated callables and classes. For your own safety and those of the codebases you love, consider canonicalizing this relative forward reference into an absolute forward reference (e.g., replace "XXXX" with "{your_package}.{your_submodule}.XXXX").
The suggested solution to this error is to change the format of our ForwardRefs. Sadly not all ForwardRefs are inside our codebase, and this is highly limiting.
I suggest Adding a "local_classes" param to beartype.door functions which maps ForwardRef string to the class itself.
Handcrafted example where this issue arises.
The text was updated successfully, but these errors were encountered: