Skip to content

Commit 2ee1c5e

Browse files
committed
Lint: Remove Version, Last-Modified, and Content-Type from check-peps.py
1 parent b39aefe commit 2ee1c5e

File tree

3 files changed

+13
-50
lines changed

3 files changed

+13
-50
lines changed

Diff for: check-peps.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@
3939
ALL_HEADERS = (
4040
"PEP",
4141
"Title",
42-
"Version",
43-
"Last-Modified",
4442
"Author",
4543
"Sponsor",
4644
"BDFL-Delegate", "PEP-Delegate",
4745
"Discussions-To",
4846
"Status",
4947
"Type",
5048
"Topic",
51-
"Content-Type",
5249
"Requires",
5350
"Created",
5451
"Python-Version",
@@ -132,16 +129,18 @@ def check_headers(lines: Sequence[str], /) -> MessageIterator:
132129
yield from _validate_pep_number(next(iter(lines), ""))
133130

134131
found_headers = {}
132+
found_header_lines: list[tuple[str, int]] = []
135133
line_num = 0
136134
for line_num, line in enumerate(lines, start=1):
137135
if line.strip() == "":
138136
headers_end_line_num = line_num
139137
break
140138
if match := HEADER_PATTERN.match(line):
141139
header = match[1]
140+
found_header_lines.append((header, line_num))
142141
if header in ALL_HEADERS:
143142
if header not in found_headers:
144-
found_headers[match[1]] = line_num
143+
found_headers[header] = None
145144
else:
146145
yield line_num, f"Must not have duplicate header: {header} "
147146
else:
@@ -151,11 +150,11 @@ def check_headers(lines: Sequence[str], /) -> MessageIterator:
151150

152151
yield from _validate_required_headers(found_headers.keys())
153152

154-
shifted_line_nums = list(found_headers.values())[1:]
155-
for i, (header, line_num) in enumerate(found_headers.items()):
153+
shifted_line_nums = [line for _, line in found_header_lines[1:]]
154+
for i, (header, line_num) in enumerate(found_header_lines):
156155
start = line_num - 1
157156
end = headers_end_line_num - 1
158-
if i < len(found_headers) - 1:
157+
if i < len(found_header_lines) - 1:
159158
end = shifted_line_nums[i] - 1
160159
remainder = "\n".join(lines[start:end]).removeprefix(f"{header}:")
161160
if remainder != "":
@@ -182,8 +181,6 @@ def _validate_header(header: str, line_num: int, content: str) -> MessageIterato
182181
yield from _validate_type(line_num, content)
183182
elif header == "Topic":
184183
yield from _validate_topic(line_num, content)
185-
elif header == "Content-Type":
186-
yield from _validate_content_type(line_num, content)
187184
elif header in {"Requires", "Replaces", "Superseded-By"}:
188185
yield from _validate_pep_references(line_num, content)
189186
elif header == "Created":
@@ -348,13 +345,6 @@ def _validate_topic(line_num: int, line: str) -> MessageIterator:
348345
yield line_num, "Topic must be sorted lexicographically"
349346

350347

351-
def _validate_content_type(line_num: int, line: str) -> MessageIterator:
352-
"""'Content-Type' must be 'text/x-rst'"""
353-
354-
if line != "text/x-rst":
355-
yield line_num, "Content-Type must be 'text/x-rst'"
356-
357-
358348
def _validate_pep_references(line_num: int, line: str) -> MessageIterator:
359349
"""`Requires`/`Replaces`/`Superseded-By` must be 'NNN' PEP IDs"""
360350

Diff for: pep_sphinx_extensions/tests/pep_lint/test_headers.py

-24
Original file line numberDiff line numberDiff line change
@@ -253,30 +253,6 @@ def test_validate_topic(line: str, expected_warnings: set):
253253
assert found_warnings == expected_warnings
254254

255255

256-
def test_validate_content_type_valid():
257-
warnings = [
258-
warning for (_, warning) in check_peps._validate_content_type(1, "text/x-rst")
259-
]
260-
assert warnings == [], warnings
261-
262-
263-
@pytest.mark.parametrize(
264-
"line",
265-
[
266-
"text/plain",
267-
"text/markdown",
268-
"text/csv",
269-
"text/rtf",
270-
"text/javascript",
271-
"text/html",
272-
"text/xml",
273-
],
274-
)
275-
def test_validate_content_type_invalid(line: str):
276-
warnings = [warning for (_, warning) in check_peps._validate_content_type(1, line)]
277-
assert warnings == ["Content-Type must be 'text/x-rst'"], warnings
278-
279-
280256
@pytest.mark.parametrize(
281257
"line",
282258
[

Diff for: pep_sphinx_extensions/tests/pep_lint/test_pep_lint.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,30 @@ def test_with_fake_pep():
1212
warnings = list(check_peps.check_peps(PEP_9002, content))
1313
assert warnings == [
1414
(1, "PEP must begin with the 'PEP:' header"),
15+
(6, "Must not have invalid header: Version"),
1516
(9, "Must not have duplicate header: Sponsor "),
1617
(10, "Must not have invalid header: Horse-Guards"),
18+
(15, "Must not have invalid header: Content-Type"),
1719
(1, "Must have required header: PEP"),
1820
(1, "Must have required header: Type"),
1921
(
2022
1,
21-
"Headers must be in PEP 12 order. Correct order: Title, Version, "
22-
"Author, Sponsor, BDFL-Delegate, Discussions-To, Status, Topic, "
23-
"Content-Type, Requires, Created, Python-Version, Post-History, "
24-
"Resolution",
23+
"Headers must be in PEP 12 order. Correct order: Title, Author, "
24+
"Sponsor, BDFL-Delegate, Discussions-To, Status, Topic, Requires, "
25+
"Created, Python-Version, Post-History, Resolution",
2526
),
2627
(4, "Author continuation lines must end with a comma"),
2728
(5, "Author line must not be over-indented"),
2829
(7, "Python-Version major part must be 1, 2, or 3: 4.0"),
29-
(
30-
8,
31-
"Sponsor entries must begin with a valid 'Name': "
32-
r"'Sponsor:\nHorse-Guards: Parade'",
33-
),
30+
(8, "Sponsor entries must begin with a valid 'Name': ''"),
31+
(9, "Sponsor entries must begin with a valid 'Name': ''"),
3432
(11, "Created must be a 'DD-mmm-YYYY' date: '1-Jan-1989'"),
3533
(12, "Delegate entries must begin with a valid 'Name': 'Barry!'"),
3634
(13, "Status must be a valid PEP status"),
3735
(14, "Topic must not contain duplicates"),
3836
(14, "Topic must be properly capitalised (Title Case)"),
3937
(14, "Topic must be for a valid sub-index"),
4038
(14, "Topic must be sorted lexicographically"),
41-
(15, "Content-Type must be 'text/x-rst'"),
4239
(16, "PEP references must be separated by comma-spaces (', ')"),
4340
(17, "Discussions-To must be a valid thread URL or mailing list"),
4441
(18, "Post-History must be a 'DD-mmm-YYYY' date: '2-Feb-2000'"),

0 commit comments

Comments
 (0)