[issue46291] [doc] First argument to raise can also be BaseException

2022-01-07 Thread Gregor Titze


New submission from Gregor Titze :

The Python Tutorial describes the first argument to the raise statement as 
follows:

"""
This must be either an exception instance or an exception class (a class that 
derives from Exception).
"""
https://docs.python.org/3/tutorial/errors.html#raising-exceptions

However, the Python Language Reference states, that exceptions should be a 
subclass or instance of BaseException.
https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-raise_stmt

I think it would be correct, to adapt the Tutorial to match the Reference.

--
assignee: docs@python
components: Documentation
messages: 409961
nosy: docs@python, gtitze
priority: normal
severity: normal
status: open
title: [doc] First argument to raise can also be BaseException
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

___
Python tracker 
<https://bugs.python.org/issue46291>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46291] [doc] First argument to raise can also be BaseException

2022-01-07 Thread Gregor Titze


Gregor Titze  added the comment:

Andre:

You mention that user-defined exceptions should inherit from Exception. This is 
totally right and explicitly stated just a bit later in 8.6 on the same page of 
the tutorial. I think this perfectly covers this concern .

However, the paragraph I refer to explains the raise statement and as stated in 
the reference, the raise statement must be followed by a class or instance 
derived from BaseException. Thus, I think it would just be accurate and people 
reading on don't stumble over this difference as I did.

Regarding the mentioned wildcard: I think it wouldn't be a real wildcard 
anymore if it didn't catch ALL exceptions. Anyway the tutorial states that it 
needs to be used with extreme caution and the example re-raises the error.

Irit:

Yes I am happy provide a patch. I would also correct the other two issues you 
mentioned.

--

___
Python tracker 
<https://bugs.python.org/issue46291>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46291] [doc] First argument to raise can also be BaseException

2022-01-07 Thread Gregor Titze


Gregor Titze  added the comment:

Irit:

I would move the paragraph starting with "The except clause may specify a 
variable after the exception name ..." and the following example before the 
paragraph starting with "All exceptions inherit from BaseException, and so it 
can be used to serve as a wildcard ..."

Or did you have another position in mind?

--

___
Python tracker 
<https://bugs.python.org/issue46291>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com