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

quantity_input decorator is un-typed #14110

Open
dstansby opened this issue Dec 6, 2022 · 4 comments
Open

quantity_input decorator is un-typed #14110

dstansby opened this issue Dec 6, 2022 · 4 comments
Labels
Bug typing related to type annotations units

Comments

@dstansby
Copy link
Contributor

dstansby commented Dec 6, 2022

Description

I'm trying to add typing to some code I use with Quantity input.ouput. Using the u.quantity_input decorator errors with mypy though, complaining that the decorator is untyped.

Expected behavior

No complaint from mypy

Actual behavior

mypy errors with

test.py:3: error: Untyped decorator makes function "speed" untyped
Found 1 error in 1 file (checked 1 source file)

Steps to Reproduce

  1. Save the following code to file
  2. run mypy --strict test.py
import astropy.units as u

@u.quantity_input
def speed(distance: u.m, time: u.s) -> u.Quantity:
    return distance / time

System Details

macOS-12.6.1-arm64-arm-64bit
Python 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:25:29) [Clang 14.0.6 ]
Numpy 1.23.4
pyerfa 2.0.0.1
astropy 5.1.1
Scipy 1.9.3
Matplotlib 3.6.2
mypy 0.982 (compiled: yes)

@dstansby dstansby added the Bug label Dec 6, 2022
@pllim pllim added the units label Dec 6, 2022
@eerovaher
Copy link
Member

See #14134 (comment)

@mhvk
Copy link
Contributor

mhvk commented Dec 7, 2022

For quantity_input, @nstarman had a nice PR but it became a bit messy; see #10655 and hence that was closed. So far, what has been implemented is the part that one can do Quantity[unit] (#10662)

@nstarman
Copy link
Member

nstarman commented Dec 7, 2022

Yeah. Typing quantity_input wouldn't actually be all that hard. I would welcome a PR. The underlying issues are that we are hesitant to add a lot of typing before an APE.

@Cadair
Copy link
Member

Cadair commented Dec 8, 2022

I will just reiterate from #14134 that quantity_inputs existing use of function annotations as not-type-hints is perfectly legitimate and should remain supported even if it learns how to read valid type hints in addition.

@mhvk mhvk added the typing related to type annotations label May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug typing related to type annotations units
Projects
None yet
Development

No branches or pull requests

6 participants