-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-104683: Rework Argument Clinic error handling #107551
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
gh-104683: Rework Argument Clinic error handling #107551
Conversation
- Introduce ClinicError and ClinicWarning - fail() raises ClinicError - warn() uses warnings.warn(msg, ClinicWarning) - the CLI runs main(), catches ClinicError, formats the error message prints to stderr and exits with an error - adapt the test suite to work with ClinicError
Ready for a new round of review! Finally, all (or most) line number are now correct. If I introduce an error in Lib/test/clinic.test.c, I now get an accurate line number. Yay! I'm not sure why some of the tests are off by one, though. Perhaps it has to do with FakeClinic. |
Tools/clinic/clinic.py
Outdated
try: | ||
self.state(line) | ||
except ClinicError as exc: | ||
raise ClinicError(str(exc), filename=exc.filename, lineno=line_number) |
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.
IMO, this is a workaround! We should ensure that line numbers are correctly updated in the state machine. Let's create an issue about this.
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.
I'd like to keep the workaround for now; it really helps to have accurate line numbers when debugging.
Co-authored-by: Alex Waygood <[email protected]>
I had an idea for how to deduplicate some code between |
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.
One last suggestion to help future maintainers -- looks great to me otherwise!
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.
Thanks! :D
Great, thank you; this PR is in a lot better shape now 😄 |
Introduce ClinicError and ClinicWarning:
In main(), catch ClinicError, format the error message,
print to stderr, and exit with an error. Adapt the test
suite accordingly.
Tools/clinic/
#104683