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
Document 'from None' in raise statement doc. #61390
Comments
Language manual, section 7.8. The raise statement has no mention of the 'from None' option. Indeed it says "if given, the second expression must be another exception class or instance", which would exclude None. Library manual, Ch 5. Built-in Exceptions, says raise new_exc from original_exc The expression following from must be an exception or None. It will be set as __cause__ on the raised exception. Setting __cause__ also implicitly sets the __suppress_context__ attribute to True, so that using raise new_exc from None effectively replaces the old exception with the new one for display purposes (e.g. converting KeyError to AttributeError, while leaving the old exception available in __context__ for introspection when debugging. I am also not sure how much applies to 3.2, but there is no version-added or -changed note with the above. |
As Terry notes, the various pieces of "from None" documentation should also have a nearby directive like: .. versionchanged: 3.3 :const:`None` permitted as ``Y`` in ``raise X from Y`` .. versionadded: 3.3 The |
We have added the from None to the documentation with a explanation and some example code. |
The patch should add something to the "The from clause is used for exception..." paragraph, to state that None is also allowed. It also adds things in a confusing order. I think the new example should go below other examples, and the changedversion and addedversion directives should be the last thing in the section. |
Hi, |
Patch with some corrections. |
The patch doesn't apply cleanly on 3.4 or default. |
I have attached a patch for 3.4, based on the patch submitted by Nitika Agarwal. The main difference is that I think it's better to be explicit and show a separate example of I will submit a patch for later versions as well. |
OK, it seems that patch applies cleanly to 3.5 and 3.6. |
Re-uploaded the patch without the typo. |
reuploaded thomir's patch issue17188_3.4.patch as is. |
Would any of the original authors be able to prepare a PR for this? Thanks. |
The double listing seems to be a glitch. Either someone else does backport or online doc change waits until I can do it. |
Patch has been applied to 3.7 and 3.6. |
Seems periods at the ends of sentences are missed. |
Thanks Serhiy. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: