summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2023-02-05 14:43:31 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2023-02-05 20:49:40 +0100
commit7249fef231c48edd7be01ed48f18cf931eee041c (patch)
tree00dd2dc15bc782afc04ea50dd1bf1f9cd509d4eb /doc
parentd32c2b067701835673750649167b785555edaa7e (diff)
downloadpylint-git-7249fef231c48edd7be01ed48f18cf931eee041c.tar.gz
[too-many-statements] Add an example for too-many-statement
Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/data/messages/t/too-many-statements/bad.py32
-rw-r--r--doc/data/messages/t/too-many-statements/details.rst1
-rw-r--r--doc/data/messages/t/too-many-statements/good.py23
-rw-r--r--doc/data/messages/t/too-many-statements/pylintrc2
4 files changed, 56 insertions, 2 deletions
diff --git a/doc/data/messages/t/too-many-statements/bad.py b/doc/data/messages/t/too-many-statements/bad.py
new file mode 100644
index 000000000..11c61c21b
--- /dev/null
+++ b/doc/data/messages/t/too-many-statements/bad.py
@@ -0,0 +1,32 @@
+import random
+
+
+def distribute_candies( # [too-many-statements]
+ children: list[Child], candies_per_child: int
+):
+ # This function is a masterpiece of code that embodies the epitome of efficiency
+ # it's also an essential part of a high-priority project with extremely tight deadlines
+ # and there is absolutely no time to refactor it to make it more concise.
+ # The lead developer on the project, who has decades of experience,
+ # has personally reviewed this implementation and deemed it good enough as it is.
+ # The person writing this code has a demanding job and multiple responsibilities,
+ # and simply does not have the luxury of spending time making this code more readable.
+ total_candies = len(children) * candies_per_child
+ eaten_candies = 0
+ # Counting candies given to each child
+ for child in children:
+ # If a child eat more than 1 candies they're going to eat all
+ # the candies for sure
+ eaten_for_child = random.choices([0, 1, candies_per_child])
+ print(
+ f"Child {child} gets {candies_per_child} candies and eat {eaten_for_child}"
+ )
+ remaining_candies_for_children = child.eat_candies(eaten_for_child)
+ if remaining_candies_for_children == 0:
+ print(f"All the candies have been devoured by {child.name}!")
+ else:
+ print(
+ f"{child.name} still have {remaining_candies_for_children} candies left."
+ )
+ eaten_candies += eaten_for_child
+ return eaten_candies, total_candies
diff --git a/doc/data/messages/t/too-many-statements/details.rst b/doc/data/messages/t/too-many-statements/details.rst
deleted file mode 100644
index ab8204529..000000000
--- a/doc/data/messages/t/too-many-statements/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/t/too-many-statements/good.py b/doc/data/messages/t/too-many-statements/good.py
index c40beb573..4736fdc1c 100644
--- a/doc/data/messages/t/too-many-statements/good.py
+++ b/doc/data/messages/t/too-many-statements/good.py
@@ -1 +1,22 @@
-# This is a placeholder for correct code for this message.
+import random
+
+
+def distribute_candies(children: list[Child], candies_per_child: int):
+ total_candies = len(children) * candies_per_child
+ eaten_candies = 0
+ for child in children:
+ eaten_candies += _distribute_candies_to_child(candies_per_child, child)
+ return eaten_candies, total_candies
+
+
+def _distribute_candies_to_child(candies_per_child: int, child: Child):
+ # If a child eat more than 1 candies they're going to eat all
+ # the candies for sure
+ eaten_for_child = random.choices([0, 1, candies_per_child])
+ print(f"Child {child} gets {candies_per_child} candies and eat {eaten_for_child}")
+ remaining_candies_for_children = child.eat_candies(eaten_for_child)
+ if remaining_candies_for_children == 0:
+ print(f"All the candies have been devoured by {child.name}!")
+ else:
+ print(f"{child.name} still have {remaining_candies_for_children} candies left.")
+ return eaten_for_child
diff --git a/doc/data/messages/t/too-many-statements/pylintrc b/doc/data/messages/t/too-many-statements/pylintrc
new file mode 100644
index 000000000..30d7a6323
--- /dev/null
+++ b/doc/data/messages/t/too-many-statements/pylintrc
@@ -0,0 +1,2 @@
+[DESIGN]
+max-statements=7