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

Type hints for derived quantities #1801

Merged
merged 12 commits into from
Jul 11, 2024

Conversation

dlakaplan
Copy link
Contributor

Using the older syntax for combining type hints and quantity input since we still support old astropy (#1709)

@dlakaplan
Copy link
Contributor Author

I had to change the docstrings to raw docstrings (r""" ... """) to avoid stricter checking for escape sequences in python 3.12.

@dlakaplan
Copy link
Contributor Author

This is broadly failing the oldestdeps. I haven't tracked it down, but it might be something we table until we update the oldest astropy.

@dlakaplan
Copy link
Contributor Author

So I think the issue with the older astropy is a conflict between the quantities decorator and typehints decorator for the return types. e.g.,

@u.quantity_input(x=u.m)
def v(x: u.Quantity) -> u.Quantity
    return x/(10*u.s)

seems to fail with the older astropy since it interprets the return type for a return unit. Without the @u.quantity_input this works fine, and in newer astropy it works. But not with the old ones. Instead we need to do:

@u.quantity_input(x=u.m)
def v(x: u.Quantity) -> u.m/u.s
    return x/(10*u.s)

and specify the units for the return rather than the type/class. Probably this is OK and combining the unit checking with type hints is still a net positive, but we might want to check back on this when we update oldestdeps to see if we can make it more uniform.

@abhisrkckl abhisrkckl merged commit a2522a7 into nanograv:master Jul 11, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants