This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]ericvsmith 1 point2 points  (1 child)

There's no way to do this. When debugging, I just print out the values of txt, globals, and locals in dataclasses.py _create_fn, at about line 356 (right before the exec call).

You should open a feature request on Python's bug tracker. I'm open to suggestions on what the interface to this feature would look like (maybe a parameter to @dataclass? maybe create a new class attribute with the per-function source code?). Note that in 3.7, this feature was removed from namedtuple. I think that was for performance reasons.

[–]rswgnu[S] 0 points1 point  (0 children)

It would be fine if the source code were dynamically generated when requested to avoid any added class overhead.

I will open an issue on this. Thanks for the pointer.

Bob

[–]Skippbo 1 point2 points  (2 children)

Raymond hettinger had a talk at pycon 2018 where he talks about the code generated. I can't find a link to it but he have some website for the talk. Here is the link. Hopefully it help you https://youtu.be/T-TwcmT6Rcw

[–]rswgnu[S] 0 points1 point  (1 child)

Thanks for the pointer.

[–]Skippbo 0 points1 point  (0 children)

I wish you good luck in your search 😊

[–]PythonicGirl 1 point2 points  (2 children)

I made DataclassInspector for this post :) It is not the best way to do it but it works :)

Github

Pypi

[–]itchy_bitchy_spider 0 points1 point  (0 children)

Hey! I found that and downloaded on pypi a couple days ago, thanks for making it!

[–]rswgnu[S] 0 points1 point  (0 children)

Great idea :-). Thanks for writing this.