Fix longdouble complex docstring to clongdouble#5952
Conversation
rwgk
left a comment
There was a problem hiding this comment.
Below is a Cursor-generated analysis. I didn't double-check the analysis (in my experience such analyses are pretty reliable).
Question
Will this change break numpy v1 compatibility?
Answer
No, this change will NOT break numpy v1 compatibility.
Analysis
The Change
The PR changes the docstring type annotation from numpy.longcomplex to numpy.clongdouble in include/pybind11/numpy.h:
- const_name("numpy.longcomplex"));
+ const_name("numpy.clongdouble"));numpy.clongdouble Availability
numpy.clongdouble has existed in numpy since at least version 1.14.0 (January 2018). Looking at numpy's source code (numpy/core/numerictypes.py), longcomplex was actually just an alias for clongdouble:
('longcomplex', 'clongdouble'), # alias mapping in numpyThis can be verified in numpy 1.14.0's source:
clongdoubleis the canonical namelongcomplexandclongfloatwere aliases pointing toclongdouble
pybind11's Minimum NumPy Requirements
Based on tests/requirements.txt, the oldest numpy versions tested are:
| Python Version | NumPy Version |
|---|---|
| CPython 3.8-3.9 | ~=1.21.5 |
| CPython 3.10 | ~=1.22.2 |
| CPython 3.11-3.12 | ~=1.26.0 |
| PyPy 3.8 | ~=1.23.0 |
All of these are well after clongdouble was introduced (1.14.0).
What Happened in NumPy 2.0
In NumPy 2.0, the deprecated alias np.longcomplex was removed, but the canonical name np.clongdouble remains available. The error message that prompted this PR states:
AttributeError: `np.longcomplex` was removed in the NumPy 2.0 release. Use `np.clongdouble` instead.
Conclusion
The PR correctly uses the canonical name numpy.clongdouble which:
- Has been available since numpy 1.14+ (2018)
- Works in both NumPy 1.x and NumPy 2.x
- Is the recommended replacement per NumPy's own guidance
Since pybind11 only tests with numpy ≥1.21.5, this change is perfectly safe and maintains full backward compatibility.
|
Thanks! |
Description
Suggested changelog entry:
long doublecomplex types to usenumpy.clongdoubleinstead of the deprecatednumpy.longcomplex(removed in NumPy 2.0).