Repository navigation
Simplify Cosmology cloning logic - #11515
Conversation
|
👋 Thank you for your draft pull request! Do you know that you can use |
|
Aha! @adrn, I see you looked at this PR. You're now caught in my nefarious scheme to improve the cosmo package. Can I has review plz? |
adrn
left a comment
There was a problem hiding this comment.
Nice! I think this is a nice refactor and only have some minor nitpicks (mostly around fixing some of the docstring language, while you're touching the code...).
On TypeError / AttributeError: What causes that TypeError to get thrown?
|
Hello @nstarman 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2021-04-11 18:36:24 UTC |
@adrn, the old code throws Edit: I would like to deprecate the AttributeError and, in future, raise a TypeError. |
|
Understood and agree AttributeError is wrong - the thing I'm not clear on is whether it should be a TypeError or a ValueError.
|
|
Thanks @adrn for the review! I think I resolved the issues and since you agree about AttributeError, I added a deprecation warning. |
adrn
left a comment
There was a problem hiding this comment.
Great - I'm happy with this (aside from the optional very minor nitpick :))!
319c2ba to
ebb9334
Compare
|
Uh oh! it fails the test because it raises it's own DeprecationWarning? I'm not familiar with Astropy's standard fix! |
|
Ah, right haha. Inside the |
Store initialization signature and arguments changelog fragment deprecation warning for AttributeError over TypeError Co-authored-by: Adrian Price-Whelan <[email protected]> Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
ebb9334 to
e806f6a
Compare
|
Only had a quick look, but just a general 👍 to the idea! |
|
(Note: test failures are unrelated) |
|
Thanks @nstarman for this! |
|
@adrn , for future reference, please don't forget to milestone. The milestone check is flaky nowadays. Also, are you sure user doc update isn't needed? I added a "whatsnew-needed" label for now but feel free to remove if you disagree. |
|
Oh yes, good to know RE: the milestone check - I scanned the checks and hit merge, but will explicitly look for milestone in the future! No docs needed: this is not a user-facing change. |
|
@pllim - why the v5.0 milestone ? If it's merged in main it will be in 4.3. |

Description
Massively simplify the cloning logic of Cosmology by storing the initialization signature and arguments on the class and instance, respectively. This is fine since Cosmo classes are immutable (expressed in old
.clonedocs).The refactor generalizes the method to work for any subclass, user-defined or not, which was a notable limitation of the former implementation.
This PR will enable the next PR, which will allow for
Cosmologyto by useful for instantiating cosmologies that are "perturbations" around the default cosmology (see #10673)Part of #10673
@mhvk @embray : Pretty much purely technical PR.
p.s. Are any new tests needed? this seems a pretty atomic change. The only reason I labelled it API is that it changes the errors that
cloneraises.p.p.s. Can I add a warning that we'll be changing the error from an Attribute to TypeError at some later date? It really shouldn't be an AttributeError.