Skip to content

Conversation

@jorenham
Copy link
Member

@jorenham jorenham commented Oct 30, 2025

closes #30095

Because stubtest is now able to pick up on the ufunc method signatures, this required updating the stubs accordingly. The ufunc stubs are pretty messy as you can see, so it took a bit of effort to get it all aligned.

@jorenham

This comment was marked as resolved.

@jorenham

This comment was marked as resolved.

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into it! A bit too bad about the __text_signature__ limitations, makes me wonder if Python has hacks around it, but I guess probably not...

@jorenham jorenham force-pushed the gh-30095 branch 2 times, most recently from 0668c81 to 26a328f Compare October 30, 2025 18:47
Co-authored-by: Sebastian Berg <[email protected]>
@jorenham jorenham changed the title BUG: ufunc method signatures BUG, TYP: ufunc method signatures Oct 30, 2025
@jorenham jorenham added this to the 2.4.0 release milestone Oct 30, 2025
@jorenham
Copy link
Member Author

jorenham commented Oct 30, 2025

Thanks for looking into it! A bit too bad about the __text_signature__ limitations, makes me wonder if Python has hacks around it, but I guess probably not...

I'm not sure about C, but with rust + pyo3 you can do things like

use pyo3::prelude::*;

#[pymodule]
pub mod example {
   use pyo3::prelude::*;

   #[pyfunction]
   #[pyo3(signature = (arg: "list[int]") -> "list[int]")]
   fn list_of_int_identity(arg: Bound<'_, PyAny>) -> Bound<'_, PyAny> {
      arg
   }
}

and

use pyo3::prelude::*;

/// This function adds two unsigned 64-bit integers.
#[pyfunction]
#[pyo3(signature = (a, b=0, /), text_signature = "(a, b=0, /)")]
fn add(a: u64, b: u64) -> u64 {
    a + b
}

docs

I think that's pretty slick (and completely irrelevant here)

@github-actions
Copy link

Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code:

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/util.py:2585: error: Unused "type: ignore" comment  [unused-ignore]

colour (https://github.com/colour-science/colour)
+ colour/phenomena/tmm.py:181: error: Unsupported operand types for / ("ndarray[tuple[Any, ...], dtype[generic[Any]]]" and "ndarray[tuple[Any, ...], dtype[generic[Any]]]")  [operator]

@jorenham
Copy link
Member Author

jorenham commented Oct 30, 2025

I took a look at the new mypy_primer error for colour (src), and I'm pretty sure that it's a false positive, related to mypy's incomplete support for the overload typing spec, which could have the same underlying problem as #30103.
It's not directly related to the changes here, and rather a consequence of mypy now being able to better understand ufuncs.

for reference, here's the static_frame primer diff source: https://github.com/static-frame/static-frame/blob/3807481e76b8305b5fb83b834cf5accdb02a5a12/static_frame/core/util.py#L2585

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I am happy, just curios if duplication is needed for the valis cases.

r"""
outer($self, A, B, /, **kwargs)
--
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplication is needed to avoid the self in the html docs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea pretty much, but for consistency's sake too

@charris charris merged commit 824e555 into numpy:main Oct 31, 2025
80 checks passed
@charris
Copy link
Member

charris commented Oct 31, 2025

Thanks Joren.

charris pushed a commit that referenced this pull request Nov 6, 2025
This fixes `inspect.signature` for

- `np.random.BitGenerator`
- `np.random.Generator`
- `np.random.MT19937`
- `np.random.PCG64`
- `np.random.PCG64DXSM`
- `np.random.Philox`
- `np.random.RandomState`
- `np.random.SFC64`
- `np.random.SeedSequence`
- `np.random.bit_generator.SeedlessSeedSequence`

This also fixes a typo in `bit_generator.pxd` that accidentally defined an empty unused class `np.random.bit_generator.SeedlessSequence`.

Related to #30104, #30114, #30121, #30124, #30126, #30137, #30138, #30140, #30143, #30146, #30147, and #30155
cakedev0 pushed a commit to cakedev0/numpy that referenced this pull request Dec 5, 2025
This fixes `inspect.signature` for

- `np.random.BitGenerator`
- `np.random.Generator`
- `np.random.MT19937`
- `np.random.PCG64`
- `np.random.PCG64DXSM`
- `np.random.Philox`
- `np.random.RandomState`
- `np.random.SFC64`
- `np.random.SeedSequence`
- `np.random.bit_generator.SeedlessSeedSequence`

This also fixes a typo in `bit_generator.pxd` that accidentally defined an empty unused class `np.random.bit_generator.SeedlessSequence`.

Related to numpy#30104, numpy#30114, numpy#30121, numpy#30124, numpy#30126, numpy#30137, numpy#30138, numpy#30140, numpy#30143, numpy#30146, numpy#30147, and numpy#30155
IndifferentArea pushed a commit to IndifferentArea/numpy that referenced this pull request Dec 7, 2025
This fixes `inspect.signature` for

- `np.random.BitGenerator`
- `np.random.Generator`
- `np.random.MT19937`
- `np.random.PCG64`
- `np.random.PCG64DXSM`
- `np.random.Philox`
- `np.random.RandomState`
- `np.random.SFC64`
- `np.random.SeedSequence`
- `np.random.bit_generator.SeedlessSeedSequence`

This also fixes a typo in `bit_generator.pxd` that accidentally defined an empty unused class `np.random.bit_generator.SeedlessSequence`.

Related to numpy#30104, numpy#30114, numpy#30121, numpy#30124, numpy#30126, numpy#30137, numpy#30138, numpy#30140, numpy#30143, numpy#30146, numpy#30147, and numpy#30155
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.

BUG: Missing signatures for ufuncs

3 participants