Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Class metadata #1

Open
wpbonelli opened this issue Feb 17, 2025 · 2 comments
Open

Class metadata #1

wpbonelli opened this issue Feb 17, 2025 · 2 comments

Comments

@wpbonelli
Copy link
Member

wpbonelli commented Feb 17, 2025

This being a consciously minimal (read: heinous) hack job at the moment, little of a decorated class' metadata survives the transformation. Tab complete doesn't work, nothing useful shown on hover, etc.

(Note I am talking about Python class metadata, not attrs field metadata.)

We want all the original metadata, modified with some new attributes: name, parent, etc.

I think we don't need to wrap/replace the class init method as is done now. Better to build on attrs as much as possible*. @xattree can wrap @attrs.define(), use field_transformer to add the new fields, and use a post-init hook to create the datatree? With that (plus maybe functools.wrap?) I think attrs will do the rest, and metadata will work.

*To guarantee metadata, attrs rewrites the classes by hand, compiles them, and registers them globally. Trickery best left to experts.

@wpbonelli
Copy link
Member Author

wpbonelli commented Feb 18, 2025

This is working now. No init wrapping necessary.

@wpbonelli
Copy link
Member Author

Not entirely working yet.

For some reason the new fields aren't showing up in hover, tab complete, etc. Only the old fields. I figured field_transformer would make this work. Maybe the mypy plugin hack is necessary too? But the VSCode python extensions runs on pyright which should be covered by dataclass_transform?

@wpbonelli wpbonelli reopened this Feb 19, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant