0

How can I type hint that a value being returned by a function is both an NumPy array and holds NumPy float32 data?

I can specify that the returned value is an array using:

def func() -> np.ndarray:
    ...

However, this does not enforce the knowledge that it is a float32 array.

I can specify that the returned value is of type float32 using:

def func() -> np.float32:
    ...

However, this does not enforce the knowledge that it is an array (as opposed to a singular scalar value).

Is there a way I can get both specified in the return type?

fuglede
  • 17,388
  • 2
  • 54
  • 99
Shiania White
  • 345
  • 6
  • 16

1 Answers1

1

This is currently impossible but is a popular feature request; see this GitHub issue which contains information on progress and possible workarounds.

fuglede
  • 17,388
  • 2
  • 54
  • 99