Skip to content

Commit ad97deb

Browse files
authored
DEV: Remove ignoring Ruff rule PGH004 (#3071)
PGH004 is use specific rule codes when using `noqa`. Additionally fixes a bug discovered by this.
1 parent 493785c commit ad97deb

File tree

8 files changed

+28
-8
lines changed

8 files changed

+28
-8
lines changed

make_release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def write_release_msg_file(
138138

139139
def strip_header(md: str) -> str:
140140
"""Remove the 'CHANGELOG' header."""
141-
return md.lstrip("# CHANGELOG").lstrip() # noqa
141+
return md.removeprefix("# CHANGELOG").lstrip()
142142

143143

144144
def version_bump(git_tag: str) -> str:

pypdf/_encryption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ class EncryptAlgorithm(tuple, Enum): # type: ignore # noqa: SLOT001
781781

782782

783783
class EncryptionValues:
784-
O: bytes # noqa
784+
O: bytes # noqa: E741
785785
U: bytes
786786
OE: bytes
787787
UE: bytes

pypdf/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class EncryptionDictAttributes:
4242
"""
4343

4444
R = "/R" # number, required; revision of the standard security handler
45-
O = "/O" # 32-byte string, required # noqa
45+
O = "/O" # 32-byte string, required # noqa: E741
4646
U = "/U" # 32-byte string, required
4747
P = "/P" # integer flag, required; permitted operations
4848
ENCRYPT_METADATA = "/EncryptMetadata" # boolean flag, optional

pypdf/generic/_data_structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ def inc_parent_counter_outline(
735735
assert parent is not None, "mypy"
736736
parent = cast("TreeObject", parent.get_object())
737737
# BooleanObject requires comparison with == not is
738-
opn = parent.get("/%is_open%", True) == True # noqa
738+
opn = parent.get("/%is_open%", True) == True # noqa: E712
739739
c = cast(int, parent.get("/Count", 0))
740740
if c < 0:
741741
c = abs(c)

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ ignore = [
162162
"N817", # CamelCase `PagesAttributes` imported as acronym `PA`
163163
"PERF203", # `try`-`except` within a loop incurs performance overhead
164164
"PGH003", # Use specific rule codes when ignoring type issues
165-
"PGH004", # Use specific rule codes when using `noqa`
166165
"PLC0206", # Extracting value from dictionary without calling `.items()`
167166
"PLR1714", # Consider merging multiple comparisons
168167
"PLW0602", # Using global for `CUSTOM_RTL_SPECIAL_CHARS` but no assignment is done

tests/scripts/test_make_release.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test the `make_release.py` script."""
2+
import sys
23
from pathlib import Path
34
from unittest import mock
45

@@ -15,6 +16,26 @@
1516
f851a532a5ec23b572d86bd7185b327a3fac6b58:::DEV: Bump codecov/codecov-action from 3 to 4 (#2430):::dependabot[bot]""".encode() # noqa: E501
1617

1718
COMMITS__VERSION_4_0_1 = DATA_PATH.joinpath("commits__version_4_0_1.json")
19+
VERSION_3_9_PLUS = sys.version_info[:2] >= (3, 9)
20+
21+
22+
@pytest.mark.skipif(not VERSION_3_9_PLUS, reason="Function uses method removeprefix added in Python 3.9")
23+
@pytest.mark.parametrize(
24+
("data", "expected"),
25+
[
26+
("", ""),
27+
("# CHANGELOG", ""),
28+
("# CHANGELOG ", ""),
29+
("# CHANGELOG ", ""),
30+
("## CHANGELOG", "## CHANGELOG"),
31+
("CHANGELOG", "CHANGELOG"),
32+
("# CHANGELOG #", "#"),
33+
]
34+
)
35+
def test_strip_header(data, expected):
36+
"""Removal of the 'CHANGELOG' header."""
37+
make_release = pytest.importorskip("make_release")
38+
assert make_release.strip_header(data) == expected
1839

1940

2041
def test_get_git_commits_since_tag():

tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def test_version_compare_equal_str():
387387
def test_version_compare_lt_str():
388388
a = Version("1.0")
389389
with pytest.raises(ValueError) as exc:
390-
a < "1.0" # noqa
390+
a < "1.0" # noqa: B015
391391
assert exc.value.args[0] == "Version cannot be compared against <class 'str'>"
392392

393393

tests/test_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,9 @@ def test_add_outline_item(pdf_file_path):
651651
reader = PdfReader(output_stream)
652652
assert reader.trailer["/Root"]["/Outlines"]["/Count"] == 3
653653
assert reader.outline[0]["/Count"] == -2
654-
assert reader.outline[0]["/%is_open%"] == False # noqa
654+
assert reader.outline[0]["/%is_open%"] == False # noqa: E712
655655
assert reader.outline[2]["/Count"] == 2
656-
assert reader.outline[2]["/%is_open%"] == True # noqa
656+
assert reader.outline[2]["/%is_open%"] == True # noqa: E712
657657
assert reader.outline[1][0]["/Count"] == 0
658658

659659

0 commit comments

Comments
 (0)