-
-
Notifications
You must be signed in to change notification settings - Fork 51
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] Deep O(1)
type-checking of @dataclasses.dataclass
fields on assignment
#391
Comments
O(1)
type-checking of @dataclasses.dataclass
fields on assignment
tl;drThe tl;dr is that you are not wrong. You're very much right. @beartype currently lacks support for deep All hope is not lost, however. @leycec will surely stop playing Japanese role-playing games someday and actually code something. Until that fateful day, you can do what @leycec should have been doing all along... Behold! A Poor Man's
|
Hi @leycec, A sad day indeed to be validated (some light-hearted pun intended) in my believes! However, very kind of you to sacrifice valued gaming time, mixed with some of your endless supply of wit, to provide more background and even a poor-persons solution ;) Albeit tempting, it does indeed make me weary to put this to production... That is not to say, I am not a believer! The question therefor becomes: how do we approach this quest? You've already identified some potential showstoppers that we can break down and tackle. The most challenging of this, to me, seems (backward) compatibility. Am I naive in thinking your unit tests would cover this, or would this require additional integration testing with dependants (sadly, this link seems down atm)? I am trying to gauge what is required of a (representative) development environment to work on this, and cover this risk. Additionally: is there documentation available for contributors? P.S.: honesty dictates I must admit such enthusiasm in me tends to wane over time, just to set some expectations on my involvement in this noble quest... To clarify, I feel 'muscling in' serves a valid purpose here: to me (but correct me if I am wrong) there are different design philosophies to |
Fetch side quest intensifies. Let's RPG this.
Indeed, your wariness is justified. Production deserves better. When even the package maintainer is begging you to "...don't do it, by all the Gods!", the thin ice you're skating on is even thinner than GitHub Copilot thought. And GitHub Copilot will do anything! 😄
...heh. You're too nice. You also don't want to go here. Deep down, you know the @beartype codebase to be an exhausting pit of doom you won't soon recover from. Nobody deep-dives into @beartype more than once. Most, not even once. There are reasons for this. That said, preserving backward compatibility for the moment is mostly trivial. Hear me out. I am boring; yet you feel compelled to listen. We:
Since this option is disabled by default and probably undocumented for years to come, basically nobody except you will ever enable this option. When enough years depressingly fly past like time itself dilating into the voracious black hole that is a metaphor for humanity's fleeting mortality, we flip this default from I'm Listening and I Kinda Like What I'm Hearing... KindaRight? Exciting plan, right? Here's how we start:
|
Well, every once in a while you feel like a trip to Mordor is in order (whatever you have to tell yourself to justify it). I have a sneaky suspicion I'll have to scratch that itch in the near future, so thank you for the work breakdown structure! As you've already defined a beartype.BeartypeStrategy for it, I recon beartype.beartype (and perhaps beartype.BeartypeConf) would have to be made aware of the new state of affairs as well? I thought I'd address that first somewhere in the coming weeks. |
...heh. You're much too kind and generous for a trip to Mordor. Oh, very well! If you'd like to tour the hideous sights, I much recommend the class BeartypeConf(object):
...
def __new__(
...
is_check_pep557_assign: bool = False,
...
) -> 'BeartypeConf': Basically, just grep for the existing optional |
Hi,
Very much taken by your library's functionality, especially the 'wire-once-and-forget' setup: much appreciated!
I have a gut-feeling this is a noob question, but either I don't have a solid grasp of the functionality offered by your library, or I cannot get seemingly basic functionality to work, that is: type enforcement of object attributes.
Going by this very simple implementation, I can verify type enforcement is performed on method calls, as configured in
__init__.py
per the documentation.main.py:
package/foo.py:
Resulting in an (expected) exception on the generated Foo.__init__(bar:str='default') method (courtesy of Python dataclasses):
However, changing main.py as follows does not yield the same result, as I would expect by said documentation stating Beartype now implicitly type-checks all annotated classes, callables, and variable assignments:
However, by now I am getting the sneaky suspicion I am doing something fundamentally wrong, as I also cannot get this example to work either, changing the content of package/foo.py as follows, yielding the same output as above:
I've also attempted to decorate with beartype (heading the warning about decorator order) and use the different BeartypeStrategys to no avail.
So... are my expectations wrong, or am I mishandling your library somehow?
The text was updated successfully, but these errors were encountered: