[issue17188] Document 'from None' in raise statement doc.
New submission from Terry J. Reedy: 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 ''' When raising a new exception (rather than using a bare raise to re-raise the exception currently being handled), the implicit exception context can be supplemented with an explicit cause by using from with raise: 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 not sure how much should be copied over, but None should be at least mentioned and perhaps there should be a cross-reference. I am also not sure how much applies to 3.2, but there is no version-added or -changed note with the above. ---------- assignee: docs@python components: Documentation messages: 181939 nosy: docs@python, ncoghlan, terry.reedy priority: normal severity: normal stage: needs patch status: open title: Document 'from None' in raise statement doc. versions: Python 3.2, Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- keywords: +easy nosy: +benjamin.peterson, ezio.melotti type: -> enhancement _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Nick Coghlan added the comment: 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 ``__suppress_context__`` attribute to suppress automatic display of the exception context ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Dennis Mårtensson added the comment: We have added the from None to the documentation with a explanation and some example code. ---------- keywords: +patch nosy: +me@dennis.is Added file: http://bugs.python.org/file29199/patch17188.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Petri Lehtinen added the comment: 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. ---------- nosy: +petri.lehtinen versions: -Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Nitika Agarwal added the comment: Hi, As suggested by Petri,I have made some changes. Please review the attached patch.Any comments and feedback are welcome. ---------- nosy: +nitika Added file: http://bugs.python.org/file34431/issue17188.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Nitika Agarwal <nitikaagarwal18@gmail.com>: Removed file: http://bugs.python.org/file34431/issue17188.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Nitika Agarwal <nitikaagarwal18@gmail.com>: Added file: http://bugs.python.org/file34432/issue17188.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Nitika Agarwal <nitikaagarwal18@gmail.com>: Removed file: http://bugs.python.org/file34432/issue17188.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Nitika Agarwal <nitikaagarwal18@gmail.com>: Added file: http://bugs.python.org/file34434/issue17188.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Nitika Agarwal added the comment: Patch with some corrections. Please review the patch attached. ---------- Added file: http://bugs.python.org/file34527/issue17188_1.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Petri Lehtinen added the comment: The patch doesn't apply cleanly on 3.4 or default. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Arfrever Frehtes Taifersar Arahesis <Arfrever.FTA@GMail.Com>: ---------- nosy: +Arfrever _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Berker Peksag <berker.peksag@gmail.com>: ---------- nosy: +berker.peksag stage: needs patch -> patch review versions: +Python 3.5 -Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Thomi Richards added the comment: 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 `raise X from None`. I will submit a patch for later versions as well. ---------- nosy: +thomir Added file: http://bugs.python.org/file44607/issue17188_3.4.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Thomi Richards added the comment: OK, it seems that patch applies cleanly to 3.5 and 3.6. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Thomi Richards added the comment: Re-uploaded the patch without the typo. ---------- Added file: http://bugs.python.org/file44618/issue17188_3.4.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Petri Lehtinen <petri@digip.org>: ---------- nosy: -petri.lehtinen _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Robert Collins <robertc@robertcollins.net>: ---------- nosy: +rbcollins _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Mariatta Wijaya <mariatta.wijaya@gmail.com>: ---------- nosy: +Mariatta _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Mariatta Wijaya added the comment: reuploaded thomir's patch issue17188_3.4.patch as is. I take no credit for this. ---------- Added file: http://bugs.python.org/file44967/issue17188_by_thomir.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Cheryl Sabella added the comment: Would any of the original authors be able to prepare a PR for this? Thanks. ---------- nosy: +csabella _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Cheryl Sabella <chekat2@gmail.com>: ---------- pull_requests: +1765 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Cheryl Sabella <chekat2@gmail.com>: ---------- pull_requests: +1765, 1766 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Terry J. Reedy added the comment: New changeset 763557eac06ba60d7c5133e4f80df8870d8f917e by terryjreedy (csabella) in branch 'master': bpo-17188: DOC: Document 'from None' in raise statement (#1671) https://github.com/python/cpython/commit/763557eac06ba60d7c5133e4f80df8870d8... ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Terry J. Reedy added the comment: The double listing seems to be a glitch. Either someone else does backport or online doc change waits until I can do it. ---------- assignee: docs@python -> terry.reedy stage: patch review -> backport needed versions: +Python 3.6, Python 3.7 -Python 3.4, Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Cheryl Sabella <chekat2@gmail.com>: ---------- pull_requests: +1949 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Mariatta Wijaya added the comment: New changeset 00b381b9a7b6b15350d1dcf7c688bf808cbf0ebb by Mariatta (csabella) in branch '3.6': bpo-17188: DOC: Document 'from None' in raise statement (GH-1671) (GH-1867) https://github.com/python/cpython/commit/00b381b9a7b6b15350d1dcf7c688bf808cb... ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Mariatta Wijaya added the comment: Patch has been applied to 3.7 and 3.6. Thanks everyone :) ---------- resolution: -> fixed stage: backport needed -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Serhiy Storchaka added the comment: Seems periods at the ends of sentences are missed. ---------- nosy: +serhiy.storchaka _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Mariatta Wijaya <mariatta.wijaya@gmail.com>: ---------- pull_requests: +1955 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Mariatta Wijaya added the comment: New changeset 9efad1e5aef32a6d8ca288793e8ee6df8782f615 by Mariatta in branch 'master': bpo-17188: add missing periods at the end of sentences (GH-1875) https://github.com/python/cpython/commit/9efad1e5aef32a6d8ca288793e8ee6df878... ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Changes by Mariatta Wijaya <mariatta.wijaya@gmail.com>: ---------- pull_requests: +1956 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Mariatta Wijaya added the comment: New changeset 60b257b01ca497d7a556e3f526704aa1b923d1ac by Mariatta in branch '3.6': bpo-17188: add missing periods at the end of sentences (GH-1875) (GH-1876) https://github.com/python/cpython/commit/60b257b01ca497d7a556e3f526704aa1b92... ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
Mariatta Wijaya added the comment: Thanks Serhiy. I added the missing periods. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17188> _______________________________________
participants (13)
-
Arfrever Frehtes Taifersar Arahesis
-
Berker Peksag
-
Cheryl Sabella
-
Dennis Mårtensson
-
Ezio Melotti
-
Mariatta Wijaya
-
Nick Coghlan
-
Nitika Agarwal
-
Petri Lehtinen
-
Robert Collins
-
Serhiy Storchaka
-
Terry J. Reedy
-
Thomi Richards