summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarutaka Kawamura <hkawamura0130@gmail.com>2022-06-05 21:17:17 +0900
committerGitHub <noreply@github.com>2022-06-05 14:17:17 +0200
commit0f1c3d37d4011f4523c7898972a1881ceb30edb5 (patch)
treef8e490811f32ec28fadea273d1dc49d4bc76c26e
parent312be0d0b8f8c38b33b19e6b83e41de886f154cd (diff)
downloadpylint-git-0f1c3d37d4011f4523c7898972a1881ceb30edb5.tar.gz
Add `overlapping-except` example (#6851)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r--doc/data/messages/o/overlapping-except/bad.py5
-rw-r--r--doc/data/messages/o/overlapping-except/details.rst1
-rw-r--r--doc/data/messages/o/overlapping-except/good.py17
-rw-r--r--doc/data/messages/o/overlapping-except/related.rst1
4 files changed, 22 insertions, 2 deletions
diff --git a/doc/data/messages/o/overlapping-except/bad.py b/doc/data/messages/o/overlapping-except/bad.py
new file mode 100644
index 000000000..eaf1e9d7f
--- /dev/null
+++ b/doc/data/messages/o/overlapping-except/bad.py
@@ -0,0 +1,5 @@
+def divide_x_by_y(x: float, y: float):
+ try:
+ print(x / y)
+ except (ArithmeticError, FloatingPointError) as e: # [overlapping-except]
+ print(f"There was an issue: {e}")
diff --git a/doc/data/messages/o/overlapping-except/details.rst b/doc/data/messages/o/overlapping-except/details.rst
deleted file mode 100644
index ab8204529..000000000
--- a/doc/data/messages/o/overlapping-except/details.rst
+++ /dev/null
@@ -1 +0,0 @@
-You can help us make the doc better `by contributing <https://github.com/PyCQA/pylint/issues/5953>`_ !
diff --git a/doc/data/messages/o/overlapping-except/good.py b/doc/data/messages/o/overlapping-except/good.py
index c40beb573..41a727545 100644
--- a/doc/data/messages/o/overlapping-except/good.py
+++ b/doc/data/messages/o/overlapping-except/good.py
@@ -1 +1,16 @@
-# This is a placeholder for correct code for this message.
+def divide_x_by_y(x: float, y: float):
+ try:
+ print(x / y)
+ except FloatingPointError as e:
+ print(f"There was a FloatingPointError: {e}")
+ except ArithmeticError as e:
+ # FloatingPointError were already caught at this point
+ print(f"There was an OverflowError or a ZeroDivisionError: {e}")
+
+# Or:
+
+def divide_x_by_y(x: float, y: float):
+ try:
+ print(x / y)
+ except ArithmeticError as e:
+ print(f"There was an OverflowError, a ZeroDivisionError or a FloatingPointError: {e}")
diff --git a/doc/data/messages/o/overlapping-except/related.rst b/doc/data/messages/o/overlapping-except/related.rst
new file mode 100644
index 000000000..c806f76df
--- /dev/null
+++ b/doc/data/messages/o/overlapping-except/related.rst
@@ -0,0 +1 @@
+- `Exception hierarchy <https://docs.python.org/3/library/exceptions.html#exception-hierarchy>`_