Repository navigation
allow metaclass keywords in Model subclasses - #11017
Conversation
bca846d to
58f2c63
Compare
|
Hello and thanks! Can you please clarify what use cases that this patch is trying to solve? Also, this is technically an API change, so it needs a change log and perhaps some user documentation update as well. And tests. |
|
@pllim, sure thing. The general use case is allowing modifications to the Model class construction process in the metaclass, rather than in new, which is not the best place for it. For instance, the Model subclasses have the class ExampleModel(Model, metaclass=_ExtendedModelMeta, some_flag=True):
passThis PR just makes this possible to implement From my experience, I want to override the signature of the evaluate method for a series of subclasses of Polynomial models. Aspects of this process are best / most efficiently accomplished at class declaration, not instantiation. Having flags allows the classes to be powerfully tailored in a manner which may be changed in the child classes and store the choices with inheritable private attributes. |
6dc97c1 to
981d31b
Compare
|
@pllim squashed with tests, change-log, and docs. |
|
Thanks. Now let's wait for review from modeling maintainers. In the meantime, we ask for your continued patience. |
|
Looks good |
|
codecov seems to be getting this wrong, none of the coverage changes are related to this PR. |
Great. I can rebase as necessary. Or vice versa if this is approved first. |
|
I'm still a little confused about this. What is the specific case motivating this? I'm not aware of any case where it is necessary to subclass It does seem like accepting some arguments to Model subclasses could be useful in general though. You mentioned something about the default |
981d31b to
90e7d0d
Compare
|
@embray The specific case that motivated this is something in my personal research. I want to override the signature of the All that happens with this PR is that class MyModel(Model, flag=True):
...doesn't error. class MyModel(Model, metaclass=_MyModelMeta, flag=True):
...
agreed! |
astropy#11017 (comment) Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
4f9a609 to
dfba4d4
Compare
|
@nstarman What do you mean by "override the signature of the evaluate method for a series of subclasses of Polynomial models" and is there a reason this couldn't be done with a simple class attribute? |
|
@nden @embray @perrygreenfield, the above discussion, while relevant to the reason I pushed this PR, I feel is actually unrelated to the content of this PR, which only enables extending the Model metaclass, and doesn't actually do so here. This PR is certainly not critical for v4.3 and could be pushed to v5.0, but... #ready-for-final-review ? |
|
I had a look at that There's certainly nothing wrong with the other approach. It's just less common and seems like overkill to me. But maybe this is purely an aesthetic/subjective question. It got me thinking, and I really don't know what a good use case is for custom arguments to But maybe there's something I'm completely missing as to why this is necessary. So I'm definitely not opposed to this PR, and and mostly just struggling to understand the use case. |
It's funny because I worked around my use case as well :p ... As I understand it, the reasons for class arguments are twofold:
In the context of https://discuss.python.org/t/motivation-for-custom-keyword-arguments-to-class-statement/8402, that example is just a flag. But one idea for something that could be done that is more complicated is: wrapping methods for numpy ufuncs versus numba. More complicated things could be done, especially since this example was just using |
|
Seems like discussions are continuing... I am going to re-milestone to 5.0 so we don't make rash decisions due to lack of time. |
259c79c to
81a49cc
Compare
|
I am re-milestoning to v5.1 as we've now branched v5.0.x |
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
|
I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks! If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here. |
81a49cc to
d88926d
Compare
|
Hmm, this was approved by @nden back in Dec 2020 but has been languishing since and yet has a "ready for final review" label. Should the label be removed? What is the current status? Thanks! |
Co-authored-by: @pllim Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
d88926d to
eb8a949
Compare
|
Personally, I think it's ready to merge. I might actually remove some of the tests. I'm not sure if the change is large enough to merit testing. |
WilliamJamieson
left a comment
There was a problem hiding this comment.
These changes seem reasonable to me.
|
Does @nden want to re-review or is an approval from @WilliamJamieson enough? |
|
William is a maintainer. |
Signed-off-by: Nathaniel Starkman (@nstarman) [email protected]
Description
In the Model class construction the metaclass
_ModelMetadoes not permit keyword arguments. Adding this option does not change anything in the class creation process, merely allows subclasses of_ModelMetato inherit methods without having to wrap them to avoid passing keyword argument.no-changelog-needed