← 返回首页
bpo-45711: use exc_value instead of exc_type to determine if exc_info is valid. Add more assertions. by iritkatriel · Pull Request #29627 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

bpo-45711: use exc_value instead of exc_type to determine if exc_info is valid. Add more assertions.#29627

Merged
iritkatriel merged 7 commits into
python:mainfrom
iritkatriel:bpo-45711-remove-exc_type_field
Nov 25, 2021
Merged

bpo-45711: use exc_value instead of exc_type to determine if exc_info is valid. Add more assertions.#29627
iritkatriel merged 7 commits into
python:mainfrom
iritkatriel:bpo-45711-remove-exc_type_field

Conversation

iritkatriel commented Nov 18, 2021
edited
Loading

Copy link
Copy Markdown
Member

This brings us closer to removing exc_type from exc_info.

Where exc_type is used, I made it use exc_value instead and added assertions that this is ok. Then when we remove exc_type it will just be a matter of removing the assertions.

https://bugs.python.org/issue45711

iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 22, 2021

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit bc889bc 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 22, 2021

gvanrossum 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 Hide comment

I noticed that in some places you require type and value to be both "nullish" or both "not nullish" (where "nullish" means either NULL or Py_None), and in other places (in particular in _assert_exception_type_is_redundant()) they are required to both be the same nullishness (i.e., both NULL or both Py_None or neither of them nullish). Is there a reason for the difference?

Comment thread Python/errors.c Outdated Show resolved Hide resolved
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>

iritkatriel commented Nov 24, 2021
edited
Loading

Copy link
Copy Markdown
Member Author

I noticed that in some places you require type and value to be both "nullish" or both "not nullish" (where "nullish" means either NULL or Py_None), and in other places (in particular in _assert_exception_type_is_redundant()) they are required to both be the same nullishness (i.e., both NULL or both Py_None or neither of them nullish). Is there a reason for the difference?

Yes. Most of these assertions are verifying that the change right next to them is valid. So if I replace if(exc_type is nullish) by if(exc_value is nullish) then I only care that their nullishness is the same. In the case of the triplets pushed to the stack, it used to be that no-exc was pushed as "NULL, NULL, None" (None for type, NULL for value and tb). I change that in this PR (ceval.c lines 5907-9 sorry - 4182-88) so now it's "NULL, None, None". There are places where "None at the top of the stack" means there is no exc_info. So when we will remove the type we need the value to be None and not NULL, otherwise we'll get segfaults.

gvanrossum 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 Hide comment

Okay, I'm through now. (Sorry for the premature send on the first batch.)

Comment thread Python/errors.c Show resolved Hide resolved
Comment thread Python/errors.c Show resolved Hide resolved
Comment thread Python/errors.c Outdated Show resolved Hide resolved
Comment thread Python/errors.c Outdated
@@ -586,7 +633,18 @@ _PyErr_ChainStackItem(_PyErr_StackItem *exc_info)
exc2 = exc_info->exc_type;

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 Hide comment

While you're here could you change 'exc' and 'exc2' to 'type' and 'type2' (or 'typ' and 'typ2')? It drives me nuts that we mix "exc[exption]" and "typ[e]" for the same concept (this must date back to Python 1 when the value was not an exception instance and the exception could be any object).

gvanrossum 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 Hide comment

All good! (Alas, I'm still stuck trying to wrap my head around the except* implementation, so that one will probably have to wait until next week.)

iritkatriel merged commit c456dfa into python:main Nov 25, 2021
remykarem pushed a commit to remykarem/cpython that referenced this pull request Dec 7, 2021
iritkatriel deleted the bpo-45711-remove-exc_type_field branch January 13, 2022 15:34
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.

4 participants

Footer

© 2026 GitHub, Inc.