-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-112634: remove dead code in PyNumber_AsSsize_t() #112635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think this can skip news... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Just as a general comment, I'm not excited by this sort of change, and I'd like to discourage future changes along these lines.
The associated issue has a "bug" label, but this is certainly not a bug - the code is working as designed and intended, and there's no user-visible issue being fixed here.
The docs for PyLong_AsSsize_t
only explicitly mention OverflowError
, but they don't explicitly say that no other error can possibly be raised.
The current implementation for PyLong_AsSsize_t
clearly cannot raise exceptions other than OverflowError
, but implementations can and do change.
The correctness of the new version of the code is in effect closely coupled to implementation details elsewhere, and in my experience this sort of long-distance coupling contributes to overall fragility, making code harder to maintain.
In this particular case it seems unlikely that a future version of PyLong_AsSsize_t
would raise new exceptions, so this particular change seems reasonable. But more generally I'd consider it a mistake to try to treat a currently unused codepath as a bug, if future changes to other parts of the codebase might cause that unused codepath to become a used codepath.
In fact, it can (TypeError and SystemError), but not in this particular code flow, as it was mentioned in the issue. IIUIC, raised exceptions are part of C API (looking on PEP 387), just as e.g. the function signature. (Despite sometimes they are documented all, sometimes only partially, as in this case.) Or not?
With this in mind, shouldn't we surround every C API call with such watchers? |
Not really, no; I don't believe there's any expectation that the C-API docs should document every exception that might possibly be raised.
No; very few things in software development are so black and white. Like most decisions, it's a judgement call that needs to be made on a case-by-case basis, with a full understanding of the context and the trade-offs. But I believe this particular change turns code that's fairly easy to reason about into code that's significantly harder to reason about, since that reasoning now requires a detailed understanding of what |
That's slightly a different story. The presence of TypeError case more or less obvious for all C API functions, operating on concrete types (i.e. not PyObject_* stuff). My point was, the set of possible exception types of a given function is still a part of API in sense of PEP 387.
Ok, I trust you opinion. |
Uh oh!
There was an error while loading. Please reload this page.