Repository navigation
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
👋 Thank you for your draft pull request! Do you know that you can use |
3d63ff9 to
c23fa82
Compare
|
Ping @mhvk @eerovaher for thoughts on MetaData. It's important to have a version of the descriptor that works with dataclasses. |
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
5fbdd67 to
5d1d92a
Compare
|
Rebasing to pick up on fixes to dev CI job. |
|
@mhvk, what do you think of this multi-step plan to enable |
|
@nstarman - sorry, anything to do with descriptors I usually need to give myself a refresher course first (and I actually wrote some fairly advanced stuff for Anyway, I now again did try to have a quick look, determined to write at least something. It mostly showed that I probably should not review, as I'm very confused... Why, e.g., is Anyway, I think I'll have to understand the problem better too... So, a suggestion that will help elucidate that (and probably just shows that I really have no experience with data classes yet): if I just go by the problems you list up front, could one not solve the first and seemingly most important one by adjusting Indeed, a quick test shows that I can get your non-frozen example to pass with (there must be a better way to tell whether something is a data class...) |
|
P.S. Night here but just remembered and putting it here so it doens't go to waste: when I looked at the meta data tests, the init and set meta ones seem identical! |
That's definitely possible, I've had a number of unsubmitted PRs where I'm trying to figure out a good way to refactor I like the idea of just modifying
Any class made with
A goal of
I'd very much like to, it's in my draft PRs to make |
|
OK, that all makes sense, including the final benefit of having as light-weight a class, with as few boilerplate method defintions as possible to distract one (I worry a bit about losing explicit is better than implicit especially on something like My preferred path would be through small steps, on |
In its current form
astropy.utils.metadata.MetaDatacannot be used as a field of a dataclass, especially not a frozen one, e.g. like in the following.Why?
MetaDatareturnsselfwhen accessed from the class. Python dataclasses use the class-level return to determine the default value of a field, so on a dataclass the default value becomes the MetaData object itself, which is incorrect.object.__setattr__. This is a known limitation of frozen dataclasses, but must be taken into account.This PR adds a new class
MetaDataField, and helper functionhasdocstringfieldfor docstring attributes on slotted dataclasses. MakingMetaDataFieldslotted should make it consume much less memory; however if we un-slot it then we can removehasdocstringfieldand reduce the (non-public) API surface introduced in this PR.In the future I hope to transition the existing
MetaDatato beMetaDataField(keeping the nameMetaData, of course) by makingMetaDatasubclassMetaDataField, then merging the two classes into 1 (calledMetaData, withMetaDataFieldas an alias). However, IMO this is not worth doing at this point, asMetaDatais used throughout Astropy,MetaDataFieldandMetaDatahave meaningfully different mechanics, and the transition will require a careful PR with deprecations, etc. If we want to do the transition in one big push, then I can move the contents to if this PR tocosmology._utils, though I would prefer to keep the metadata machinery public.This PR is necessary for my plans to make
Cosmologya dataclass!