Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make @validate_quantities compatible with from __future__ import annotations #2506

Merged

Conversation

namurphy
Copy link
Member

@namurphy namurphy commented Feb 6, 2024

Currently, @validate_quantities does not work in files when there is a from __future__ import annotations statement which postpones the evaluation of annotations. The purpose of this PR is to change that.

With postponed evaluation of annotations, the annotations become strings. For @particle_input, we were able to fix this by using typing.get_type_hints.

I'm starting with a failing test to get a better idea of where this goes wrong.

Closes #2492. Similar to #2479.

@github-actions github-actions bot added testing plasmapy.utils Related to the plasmapy.utils subpackage labels Feb 6, 2024
Copy link

codecov bot commented Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.42%. Comparing base (48750b0) to head (3a4e204).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2506   +/-   ##
=======================================
  Coverage   94.42%   94.42%           
=======================================
  Files         107      107           
  Lines        9496     9496           
  Branches     2189     2189           
=======================================
  Hits         8967     8967           
  Misses        342      342           
  Partials      187      187           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added the bug Issues describing unexpected behavior or defects. Remember: a bug is a sign of a missing test! label Feb 6, 2024
@namurphy namurphy added this to the v2024.5.0 milestone Feb 6, 2024
@namurphy
Copy link
Member Author

It turns out this is more difficult than @particle_input and I'm not sure yet how to fix this. Hm...

@namurphy namurphy added bugfix Pull requests that fix a bug. Remember: a bug is a sign of a missing test! and removed bug Issues describing unexpected behavior or defects. Remember: a bug is a sign of a missing test! labels May 14, 2024
@JaydenR2305
Copy link
Member

JaydenR2305 commented Jul 3, 2024

def __call__(self, f):
"""
Decorate a function.
Parameters
----------
f
Function to be wrapped
Returns
-------
function
wrapped function of ``f``
"""
self.f = f
wrapped_sign = inspect.signature(f)
@preserve_signature
@functools.wraps(f)
def wrapper(*args, **kwargs):
# combine args and kwargs into dictionary

I think wrapped_sign = inspect.signature(f) -> wrapped_sign = inspect.signature(f, eval_string=True) does the trick :) @namurphy

@github-actions github-actions bot added the python Pull requests that update Python code label Jul 3, 2024
@namurphy namurphy marked this pull request as ready for review July 3, 2024 19:47
@namurphy namurphy requested review from rocco8773 and a team as code owners July 3, 2024 19:47
@namurphy namurphy added status: ready for review PRs that are ready for code review and removed status: dormant PRs that are stalled labels Jul 3, 2024
@namurphy
Copy link
Member Author

namurphy commented Jul 3, 2024

I think wrapped_sign = inspect.signature(f) -> wrapped_sign = inspect.signature(f, eval_string=True) does the trick :) @namurphy

@JaydenR2305 — Great job figuring this out! I had been pretty lost on how to address this, so thank you! I made sure to include you as a co-author on the commit.

@namurphy namurphy merged commit 7837e00 into PlasmaPy:main Jul 3, 2024
25 checks passed
@namurphy namurphy deleted the validate_quantities-from-future-annotations branch July 3, 2024 23:35
@github-actions github-actions bot removed the status: ready for review PRs that are ready for code review label Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Pull requests that fix a bug. Remember: a bug is a sign of a missing test! plasmapy.utils Related to the plasmapy.utils subpackage python Pull requests that update Python code testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants