MAINT: numpy.i: Replace deprecated sprintf with snprintf#31056
Conversation
snprintfsprintf with snprintf
|
@denproc AI does a nice job here. If you want to practice, that would be fine. |
|
Hi @charris, I have addressed both Could you please let me know if there are any other outstanding issues and if I should also suggest megring it to maintenance branches for backport? |
|
@denproc I suggested AI because it produced cleaner, more readable code. |
|
@charris, could you clarify what specifically could be improved for readability? I initially tried to keep the changes minimal and local, but I’m happy to restructure it to reduce duplications if that’s preferred. |
|
I find the code here messy and overly verbose. Why not try AI yourself for suggestions? |
|
@charris, I did try an AI-generated rewrite from scratch, but it seemed to keep the same inline snprintf/buffer bookkeeping structure, so I'm not sure it's actually cleaner than the current patch. Codex suggestions: |
|
Note that the variable names don't clutter the code, keeps things on single lines, which makes it much easier to read. The difference I got using AI was similar: I haven't checked it for correctness, I just wanted to see what it looked like. We should probably have |
|
@charris thanks! To address the deprecation issue, I updated the code and replaced There are still potential improvements (avoiding repeated |
|
Thanks @denproc . That was much easier to review for correctness with the minimal changes. The AI was doing some extra optimizations, but I doubt is matters here. |
|
Note that the hot paths in both functions involved are already taken care of, speed in the error paths doesn't matter much. |
|
The only remaining useful improvements I see in the AI diff are the comments, and the |
MAINT: numpy.i: Replace deprecated `sprintf` with `snprintf` (#31056)
PR summary
This PR is for #31055.
The suggested changes in
tools/swig/numpy.ireplace deprecatedsprintfwithsnprintf.Similar issue was raised in #30997 and resolved in #30998.
First time committer introduction
Hi, I'm Denis Prokopenko, Researcher at King's College London. My main use of
numpyis development of medical imaging methods. This particular PR was inspired by similar changes introduced in STIR UCL/STIR#1699.AI Disclosure
No AI tools used