Skip to content

Commit c78f68d

Browse files
authored
DEV: Remove ignore Ruff rule ANN204 (#3099)
ANN204: Missing return type annotation for special method.
1 parent c914a62 commit c78f68d

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

pypdf/_page.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class Transformation:
169169

170170
# 9.5.4 Coordinate Systems for 3D
171171
# 4.2.2 Common Transformations
172-
def __init__(self, ctm: CompressedTransformationMatrix = (1, 0, 0, 1, 0, 0)):
172+
def __init__(self, ctm: CompressedTransformationMatrix = (1, 0, 0, 1, 0, 0)) -> None:
173173
self.ctm = ctm
174174

175175
@property

pypdf/_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class classproperty: # noqa: N801
515515
that can be accessed directly from the class.
516516
"""
517517

518-
def __init__(self, method=None): # type: ignore # noqa: ANN001
518+
def __init__(self, method=None) -> None: # type: ignore # noqa: ANN001
519519
self.fget = method
520520

521521
def __get__(self, instance, cls=None) -> Any: # type: ignore # noqa: ANN001

pypdf/annotations/_markup_annotations.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MarkupAnnotation(AnnotationDictionary, ABC):
4949
5050
"""
5151

52-
def __init__(self, *, title_bar: Optional[str] = None):
52+
def __init__(self, *, title_bar: Optional[str] = None) -> None:
5353
if title_bar is not None:
5454
self[NameObject("/T")] = TextStringObject(title_bar)
5555

@@ -75,7 +75,7 @@ def __init__(
7575
open: bool = False,
7676
flags: int = NO_FLAGS,
7777
**kwargs: Any,
78-
):
78+
) -> None:
7979
super().__init__(**kwargs)
8080
self[NameObject("/Subtype")] = NameObject("/Text")
8181
self[NameObject("/Rect")] = RectangleObject(rect)
@@ -100,7 +100,7 @@ def __init__(
100100
border_color: Optional[str] = "000000",
101101
background_color: Optional[str] = "ffffff",
102102
**kwargs: Any,
103-
):
103+
) -> None:
104104
super().__init__(**kwargs)
105105
self[NameObject("/Subtype")] = NameObject("/FreeText")
106106
self[NameObject("/Rect")] = RectangleObject(rect)
@@ -156,7 +156,7 @@ def __init__(
156156
rect: Union[RectangleObject, Tuple[float, float, float, float]],
157157
text: str = "",
158158
**kwargs: Any,
159-
):
159+
) -> None:
160160
super().__init__(**kwargs)
161161
self.update(
162162
{
@@ -193,7 +193,7 @@ def __init__(
193193
self,
194194
vertices: List[Vertex],
195195
**kwargs: Any,
196-
):
196+
) -> None:
197197
super().__init__(**kwargs)
198198
if len(vertices) == 0:
199199
raise ValueError("A polygon needs at least 1 vertex with two coordinates")
@@ -217,7 +217,7 @@ def __init__(
217217
*,
218218
interior_color: Optional[str] = None,
219219
**kwargs: Any,
220-
):
220+
) -> None:
221221
if "interiour_color" in kwargs:
222222
deprecation_with_replacement("interiour_color", "interior_color", "5.0.0")
223223
interior_color = kwargs["interiour_color"]
@@ -246,7 +246,7 @@ def __init__(
246246
highlight_color: str = "ff0000",
247247
printing: bool = False,
248248
**kwargs: Any,
249-
):
249+
) -> None:
250250
super().__init__(**kwargs)
251251
self.update(
252252
{
@@ -269,7 +269,7 @@ def __init__(
269269
*,
270270
interior_color: Optional[str] = None,
271271
**kwargs: Any,
272-
):
272+
) -> None:
273273
if "interiour_color" in kwargs:
274274
deprecation_with_replacement("interiour_color", "interior_color", "5.0.0")
275275
interior_color = kwargs["interiour_color"]
@@ -295,7 +295,7 @@ def __init__(
295295
self,
296296
vertices: List[Tuple[float, float]],
297297
**kwargs: Any,
298-
):
298+
) -> None:
299299
super().__init__(**kwargs)
300300
if len(vertices) == 0:
301301
raise ValueError("A polygon needs at least 1 vertex with two coordinates")

pypdf/annotations/_non_markup_annotations.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(
2222
target_page_index: Optional[int] = None,
2323
fit: Fit = DEFAULT_FIT,
2424
**kwargs: Any,
25-
):
25+
) -> None:
2626
super().__init__(**kwargs)
2727
if TYPE_CHECKING:
2828
from ..types import BorderArrayType
@@ -84,7 +84,7 @@ def __init__(
8484
parent: Optional[DictionaryObject] = None,
8585
open: bool = False,
8686
**kwargs: Any,
87-
):
87+
) -> None:
8888
super().__init__(**kwargs)
8989
self.update(
9090
{

pypdf/generic/_fit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class Fit:
77
def __init__(
88
self, fit_type: str, fit_args: Tuple[Union[None, float, Any], ...] = ()
9-
):
9+
) -> None:
1010
from ._base import FloatObject, NameObject, NullObject, NumberObject
1111

1212
self.fit_type = NameObject(fit_type)

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ ignore = [
116116
"A001", # Variable is shadowing a Python builtin
117117
"A002", # Function argument is shadowing a Python builtin
118118
"A005", # Module shadows a Python standard-library module
119-
"ANN204", # Missing return type annotation for special method `__init__`
120119
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
121120
"ARG001", # Unused function argument
122121
"ARG002", # Unused method argument

tests/__init__.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import concurrent.futures
22
import ssl
3+
import sys
34
import urllib.request
45
from pathlib import Path
56
from typing import Dict, List, Optional
67
from urllib.error import HTTPError
78

9+
if sys.version_info >= (3, 11):
10+
from typing import Self
11+
else:
12+
from typing_extensions import Self
13+
814
import yaml
915

1016
from pypdf.generic import DictionaryObject, IndirectObject
@@ -85,7 +91,7 @@ def normalize_warnings(caplog_text: str) -> List[str]:
8591

8692

8793
class ReaderDummy:
88-
def __init__(self, strict=False):
94+
def __init__(self, strict=False) -> None:
8995
self.strict = strict
9096

9197
def get_object(self, indirect_reference):
@@ -150,17 +156,17 @@ def test_csv_consistency():
150156
class PILContext:
151157
"""Allow changing the PIL/Pillow configuration for some limited scope."""
152158

153-
def __init__(self):
159+
def __init__(self) -> None:
154160
self._saved_load_truncated_images = False
155161

156-
def __enter__(self):
162+
def __enter__(self) -> Self:
157163
# Allow loading incomplete images.
158164
from PIL import ImageFile
159165
self._saved_load_truncated_images = ImageFile.LOAD_TRUNCATED_IMAGES
160166
ImageFile.LOAD_TRUNCATED_IMAGES = True
161167
return self
162168

163-
def __exit__(self, type_, value, traceback):
169+
def __exit__(self, type_, value, traceback) -> Optional[bool]:
164170
from PIL import ImageFile
165171
ImageFile.LOAD_TRUNCATED_IMAGES = self._saved_load_truncated_images
166172
if type_:

0 commit comments

Comments
 (0)