Skip to content

Commit 4036863

Browse files
[doc] Make sure that doc examples are of a reasonable length (#8135)
And upgrade existing unreasonable length. Reading ease is drastically reduced on read the doc after 103 chars (Because of horizontal scrolling)
1 parent df85f7a commit 4036863

File tree

15 files changed

+48
-14
lines changed

15 files changed

+48
-14
lines changed

.pre-commit-config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ repos:
6060
additional_dependencies:
6161
[flake8-bugbear==23.1.20, flake8-typing-imports==1.14.0]
6262
exclude: *fixtures
63+
- repo: https://github.com/PyCQA/flake8
64+
rev: 6.0.0
65+
hooks:
66+
- id: flake8
67+
name: line-length-doc
68+
files: doc/data/messages
69+
args: ["--config", "doc/data/.flake8"]
6370
- repo: local
6471
hooks:
6572
- id: pylint

doc/data/.flake8

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
select =
3+
E501,
4+
# Reading ease is drastically reduced on read the doc after 103 chars
5+
# (Because of horizontal scrolling)
6+
max-line-length=103

doc/data/messages/b/bad-exception-cause/bad.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ def divide(x, y):
33
try:
44
result = x / y
55
except ZeroDivisionError:
6-
raise ValueError(f"Division by zero when dividing {x} by {y} !") from result # [bad-exception-cause]
6+
# +1: [bad-exception-cause]
7+
raise ValueError(f"Division by zero when dividing {x} by {y} !") from result
78
return result

doc/data/messages/c/class-variable-slots-conflict/bad.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class Person:
2-
__slots__ = ("age", "name", "say_hi",) # [class-variable-slots-conflict, class-variable-slots-conflict, class-variable-slots-conflict]
2+
# +1: [class-variable-slots-conflict, class-variable-slots-conflict, class-variable-slots-conflict]
3+
__slots__ = ("age", "name", "say_hi")
34
name = None
45

56
def __init__(self, age, name):
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
NUMBERS = [1, 2, 3]
22

3-
DOUBLED_NUMBERS = dict([(number, number * 2) for number in NUMBERS]) # [consider-using-dict-comprehension]
3+
# +1: [consider-using-dict-comprehension]
4+
DOUBLED_NUMBERS = dict([(number, number * 2) for number in NUMBERS])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pyupgrade_ can fix this issue automatically.
2+
3+
.. _pyupgrade: https://github.com/asottile/pyupgrade
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
from string import Template
22

3-
menu = ('eggs', 'spam', 42.4)
3+
menu = ("eggs", "spam", 42.4)
44

5-
old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string]
5+
old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string]
66
beginner_order = menu[0] + " and " + menu[1] + ": " + str(menu[2]) + " ¤"
77
joined_order = " and ".join(menu[:2])
8-
format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2]) # [consider-using-f-string]
9-
named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format(eggs=menu[0], spam=menu[1], price=menu[2]) # [consider-using-f-string]
10-
template_order = Template('$eggs and $spam: $price ¤').substitute(eggs=menu[0], spam=menu[1], price=menu[2])
8+
# +1: [consider-using-f-string]
9+
format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2])
10+
# +1: [consider-using-f-string]
11+
named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format(
12+
eggs=menu[0], spam=menu[1], price=menu[2]
13+
)
14+
template_order = Template("$eggs and $spam: $price ¤").substitute(
15+
eggs=menu[0], spam=menu[1], price=menu[2]
16+
)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
NUMBERS = [1, 2, 2, 3, 4, 4]
22

3-
UNIQUE_EVEN_NUMBERS = set([number for number in NUMBERS if number % 2 == 0]) # [consider-using-set-comprehension]
3+
# +1: [consider-using-set-comprehension]
4+
UNIQUE_EVEN_NUMBERS = set([number for number in NUMBERS if number % 2 == 0])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pyupgrade_ can fix this issue automatically.
2+
3+
.. _pyupgrade: https://github.com/asottile/pyupgrade
+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
FRUIT = ["apricot", "blackcurrant", "cantaloupe", "dragon fruit", "elderberry", "fig", "grapefruit"] # [line-too-long]
1+
# +1: [line-too-long]
2+
FRUIT = ["apricot", "blackcurrant", "cantaloupe", "dragon fruit", "elderberry", "fig", "grapefruit", ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[MAIN]
2+
max-line-length=100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
If a function is not using any class attribute it can be a ``@staticmethod``,
2+
or a function outside the class.

doc/data/messages/n/no-self-use/good.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""If a function is not using any class attribute it can be a @staticmethod, or a function outside the class."""
2-
31
def developer_greeting():
42
print("Greetings developer!")
53

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
def can_be_divided_by_two_and_are_not_zero(x, y, z):
22
# Maximum number of boolean expressions in an if statement (by default 5)
3-
if (x and y and z) and (x % 2 == 0 and y % 2 == 0 and z % 2 == 0): # [too-many-boolean-expressions]
3+
# +1: [too-many-boolean-expressions]
4+
if (x and y and z) and (x % 2 == 0 and y % 2 == 0 and z % 2 == 0):
45
pass
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
print("Today is {0}, so tomorrow will be {1}".format("Monday", "Tuesday", "Wednesday")) # [too-many-format-args]
1+
# +1: [too-many-format-args]
2+
print("Today is {0}, so tomorrow will be {1}".format("Monday", "Tuesday", "Wednesday"))

0 commit comments

Comments
 (0)