Argument-Clinic / cpython

The Python programming language
https://www.python.org/
Other
1 stars 0 forks source link

Get rid of global state in `fail` and `warn` #35

Closed erlend-aasland closed 8 months ago

erlend-aasland commented 10 months ago

Here's an experiment I thought of earlier today, as a step towards error handling without global state. One of the biggest pains wrt. getting rid of the clinic global is that fail depends on it too much. So here's the experiment:

It is a crude change, but it kind of works, and I think it might be an improvement (if polished a little bit).

Side-effects:

IMO, we should just use a variety of custom exceptions, catch these during parsing, format the error message and reraise it (for either the CLI or the test suite to catch).

erlend-aasland commented 10 months ago

After the latest yak-shaving, the diff for this PR is now greatly reduced.

erlend-aasland commented 9 months ago

Victor had some remarks about this PR; I'll try to address them tomorrow:

erlend-aasland commented 9 months ago
  • it is unclear what happens if you pass lineno but not filename

Come to think of it, that is also a concern with the current code; this PR does not alter the status quo.

vstinner commented 9 months ago

I wrote a different approach: https://github.com/python/cpython/pull/114752

Maybe some of these changes are still relevent with my change, I didn't dig into the code yet.

erlend-aasland commented 8 months ago

Upstreamed as python/cpython#115510