FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104683: Rework Argument Clinic error handling by erlend-aasland · Pull Request #107551 · python/cpython · GitHub

/ cpython Public

gh-104683: Rework Argument Clinic error handling - #107551

Merged
erlend-aasland merged 31 commits into
python:mainfrom
erlend-aasland:clinic/warn-and-fail
Aug 3, 2023
Merged

gh-104683: Rework Argument Clinic error handling#107551
erlend-aasland merged 31 commits into
python:mainfrom
erlend-aasland:clinic/warn-and-fail

Conversation

erlend-aasland commented Aug 1, 2023
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

Introduce ClinicError and ClinicWarning:

  • fail() raises ClinicError
  • warn() uses warnings.warn(msg, ClinicWarning)

In main(), catch ClinicError, format the error message,
print to stderr, and exit with an error. Adapt the test
suite accordingly.

erlend-aasland and others added 10 commits July 30, 2023 00:33
- 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
Comment thread Tools/clinic/clinic.py Outdated
Comment thread Lib/test/test_clinic.py
Comment thread Lib/test/test_clinic.py Outdated
Comment thread Tools/clinic/clinic.py Outdated
Comment thread Tools/clinic/clinic.py Outdated
Comment thread Lib/test/test_clinic.py Outdated
Comment thread Lib/test/test_clinic.py Outdated
Comment thread Lib/test/test_clinic.py Outdated
Comment thread Lib/test/test_clinic.py Outdated
Comment thread Tools/clinic/clinic.py
erlend-aasland marked this pull request as ready for review August 2, 2023 14:58

Copy link
Copy Markdown
Contributor Author

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.

Comment thread Tools/clinic/clinic.py Outdated
Comment on lines +4612 to +4615
try:
self.state(line)
except ClinicError as exc:
raise ClinicError(str(exc), filename=exc.filename, lineno=line_number)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'd like to keep the workaround for now; it really helps to have accurate line numbers when debugging.

Comment thread Tools/clinic/clinic.py Outdated
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

Copy link
Copy Markdown
Member

I had an idea for how to deduplicate some code between warn_and_fail() and the main() function -- made a PR to your branch at erlend-aasland#49

AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

One last suggestion to help future maintainers -- looks great to me otherwise!

Comment thread Lib/test/test_clinic.py

AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks! :D

erlend-aasland enabled auto-merge (squash) August 2, 2023 23:39

Copy link
Copy Markdown
Contributor Author

Great, thank you; this PR is in a lot better shape now 😄

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL