Skip to content

Conversation

@jorenham
Copy link
Member

This fixes the inspect.signature errors for 50+ methods of the numpy scalar types. To avoid code duplication, I added a cute little helper function that takes care of both the method docstrings of ndarray and generic at the same time, as well as the __text_signature__.

To make things a bit easer for myself, I simplified the ndarray-referencing docstrings of the generic methods a bit, so that they fit on one line. But it could easily be expanded now, or even automatically kept in sync with the ndarray method docs.

This also adds docstrings to generic.to_device() and generic.tobytes(), because they were completely missing.

Anyway, to make a long story even longer; the following generic and longlong methods will now no longer cause inspect.signature to raise a ValueError (puns intended), including:

  • np.generic.__array_namespace__
  • np.generic.__copy__
  • np.generic.__deepcopy__
  • np.generic.all
  • np.generic.any
  • np.generic.argmax
  • np.generic.argmin
  • np.generic.argsort
  • np.generic.astype
  • np.generic.byteswap
  • np.generic.choose
  • np.generic.clip
  • np.generic.compress
  • np.generic.conj
  • np.generic.conjugate
  • np.generic.copy
  • np.generic.cumprod
  • np.generic.cumsum
  • np.generic.diagonal
  • np.generic.dump
  • np.generic.dumps
  • np.generic.fill
  • np.generic.flatten
  • np.generic.getfield
  • np.generic.item
  • np.generic.max
  • np.generic.mean
  • np.generic.min
  • np.generic.nonzero
  • np.generic.prod
  • np.generic.put
  • np.generic.ravel
  • np.generic.repeat
  • np.generic.reshape
  • np.generic.resize
  • np.generic.round
  • np.generic.searchsorted
  • np.generic.setfield
  • np.generic.setflags
  • np.generic.sort
  • np.generic.squeeze
  • np.generic.std
  • np.generic.sum
  • np.generic.swapaxes
  • np.generic.take
  • np.generic.to_device
  • np.generic.tobytes
  • np.generic.tofile
  • np.generic.tolist
  • np.generic.trace
  • np.generic.transpose
  • np.generic.var
  • np.generic.view
  • np.ulonglong.bit_count
  • np.longlong.bit_count

Related to #30104, #30114, #30121, #30124, #30126, #30137, #30138, #30140, #30143, #30146, #30147, #30155, and #30164, #30169

@jorenham jorenham added this to the 2.4.0 release milestone Nov 11, 2025
@charris charris merged commit 5350548 into numpy:main Nov 15, 2025
80 checks passed
@charris
Copy link
Member

charris commented Nov 15, 2025

Thanks Joren.

@jorenham jorenham deleted the fix-generic-method-signatures branch November 15, 2025 19:03
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.

2 participants