Skip to content

Revert deprecation of make_function_with_signature - #8624

Merged
bsipocz merged 2 commits into
astropy:masterfrom
larrybradley:make-func-sig
Apr 24, 2019
Merged

bsipocz merged 2 commits into
astropy:masterfrom
larrybradley:make-func-sig

Conversation

@larrybradley

Copy link
Copy Markdown
Member

The make_function_with_signature function was deprecated in #7554 (11bca39). However, it is still used in modeling/core.py to dynamically add keyword arguments to the __call__ method of some models.

As a result, cryptic AstropyDeprecationWarnings are currently being issued whenever modeling is imported:

>>> from astropy.modeling import models
WARNING: AstropyDeprecationWarning: This function is no longer needed, directly use `inspect.Signature`. [astropy.modeling.core]
WARNING: AstropyDeprecationWarning: This function is no longer needed, directly use `inspect.Signature`. [astropy.modeling.core]
WARNING: AstropyDeprecationWarning: This function is no longer needed, directly use `inspect.Signature`. [astropy.modeling.core]
WARNING: AstropyDeprecationWarning: This function is no longer needed, directly use `inspect.Signature`. [astropy.modeling.core]
>>> from astropy.modeling.models import Gaussian2D
WARNING: AstropyDeprecationWarning: This function is no longer needed, directly use `inspect.Signature`. [astropy.modeling.core]
WARNING: AstropyDeprecationWarning: This function is no longer needed, directly use `inspect.Signature`. [astropy.modeling.core]
WARNING: AstropyDeprecationWarning: This function is no longer needed, directly use `inspect.Signature`. [astropy.modeling.core]
WARNING: AstropyDeprecationWarning: This function is no longer needed, directly use `inspect.Signature`. [astropy.modeling.core]

Further, it's causing CI tests to fail in photutils (this is how I discovered the issue) because astropy deprecations are treated as exceptions by default in astropy.tests.helper.enable_deprecations_as_exceptions.

My initial PR attempt (larrybradley@293b7a1) to replace those remaining make_function_with_signature calls with inspect.Signature failed. I don't see an easy way to replicate the make_function_with_signature usage in modeling with inspect.Signature (if it's possible at all). For example, make_function_with_signature takes a varkwargs argument (e.g. **kwargs; see example use in modeling/core.py here: https://github.com/astropy/astropy/blob/master/astropy/modeling/core.py#L419) that is not allowed as a inspect.Parameter name. Also, modeling uses a update_wrapper method to make it look like the dynamically-created __call__ method was defined in the class (by defining __module__, __doc__, etc. on the new function). That machinery depends on make_function_with_signature returning an actual function.

This PR simply reverts the deprecation of make_function_with_signature since it's still being used in astropy.modeling (we shouldn't be issuing deprecation warnings from our own code). I think it's the most sensible thing to do for the v3.2 release, unless someone can quickly figure out how to refactor modeling to remove the remaining make_function_with_signature calls.

@bsipocz

bsipocz commented Apr 24, 2019

Copy link
Copy Markdown
Member

Thank you @larrybradley for the very quick fix. I agree that we should revert rather than ship a broken solution.

If someone has strong feelings that the deprecation has to go into 3.2 to be able to remove it in 4.0 then please open a PR asap.

@bsipocz

bsipocz commented Apr 24, 2019

Copy link
Copy Markdown
Member

This is all green except the docs build that I'm dealing with separately.

@bsipocz
bsipocz merged commit e0d4b00 into astropy:master Apr 24, 2019
@larrybradley
larrybradley deleted the make-func-sig branch April 24, 2019 13:27
@mwcraig

mwcraig commented Apr 24, 2019

Copy link
Copy Markdown
Member

Thanks for this fix @larrybradley!

@pllim

pllim commented Apr 24, 2019

Copy link
Copy Markdown
Member

@perrygreenfield , if this function is not used in your refactored code, then we might be able to revisit the deprecation once your refactored modeling is in. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants