BUG, TYP: ufunc method signatures#30104
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
seberg
left a comment
There was a problem hiding this comment.
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...
0668c81 to
26a328f
Compare
Co-authored-by: Sebastian Berg <sebastianb@nvidia.com>
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
}I think that's pretty slick (and completely irrelevant here) |
|
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]
|
|
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. 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 |
seberg
left a comment
There was a problem hiding this comment.
Thanks I am happy, just curios if duplication is needed for the valis cases.
| r""" | ||
| outer($self, A, B, /, **kwargs) | ||
| -- | ||
|
|
There was a problem hiding this comment.
The duplication is needed to avoid the self in the html docs?
There was a problem hiding this comment.
Yea pretty much, but for consistency's sake too
|
Thanks Joren. |
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
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
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
| accumulate($self, array, /, axis=0, dtype=None, out=None) | ||
| -- | ||
|
|
||
| accumulate(array, axis=0, dtype=None, out=None) |
There was a problem hiding this comment.
For my understanding, why is the signature needed twice?
There was a problem hiding this comment.
The first one is removed from the docstring and only used by e.g. inspect.signature. The second one is there for documentation purposes only.
closes #30095
Because stubtest is now able to pick up on the
ufuncmethod 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.