Replies: 1 comment
-
|
Ho, ho! Such a fascinating discussion. Let's promote this to a fully-fledged feature request at issue #494. Indeed, @beartype should support [PEP 681](https://peps.python.org/pep-0681 via the Thanks so much for the deep dive on custom dataclasses, @acecchini. Let's get this done... somehow. 🫡 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! First thanks for making beartype a reality, this is one of the best library I have come accross and use it everyday!
I have created a custom behaved class (called TransitionClass) which is generated similarly as dataclasses are. I have created a metaclass (TransitionMeta) which processes the namespace of my class body and generates automatically different methods through the 'exec' command, as done in dataclasses. In particular it generates an 'init' method automatically. The 'init' method head is type annotated correctly, however, as in dataclasses, the default value for fields which have a default factory function is a sentinel '_HAS_DEFAULT_FACTORY' which is an instance of '_HAS_DEFAULT_FACTORY_CLASS', which obviously is not of the right type.
I suppose that if I just decorate my init method with beartype I will therefore get an error. How did you do to bypass this bottleneck in dataclasses?
Also since TransitionClass behave similarly as dataclasses I have decorated TransitionMeta with typing.dataclass_transform. Can I then directly decorate TransitionClass's init with beartype?
Many thanks :)
Beta Was this translation helpful? Give feedback.
All reactions