Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Remove ignore Ruff rule ANN204 #3099

Merged
merged 8 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Transformation:

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

@property
Expand Down
2 changes: 1 addition & 1 deletion pypdf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class classproperty: # noqa: N801
that can be accessed directly from the class.
"""

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

def __get__(self, instance, cls=None) -> Any: # type: ignore # noqa: ANN001
Expand Down
18 changes: 9 additions & 9 deletions pypdf/annotations/_markup_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MarkupAnnotation(AnnotationDictionary, ABC):

"""

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

Expand All @@ -75,7 +75,7 @@ def __init__(
open: bool = False,
flags: int = NO_FLAGS,
**kwargs: Any,
):
) -> None:
super().__init__(**kwargs)
self[NameObject("/Subtype")] = NameObject("/Text")
self[NameObject("/Rect")] = RectangleObject(rect)
Expand All @@ -100,7 +100,7 @@ def __init__(
border_color: Optional[str] = "000000",
background_color: Optional[str] = "ffffff",
**kwargs: Any,
):
) -> None:
super().__init__(**kwargs)
self[NameObject("/Subtype")] = NameObject("/FreeText")
self[NameObject("/Rect")] = RectangleObject(rect)
Expand Down Expand Up @@ -156,7 +156,7 @@ def __init__(
rect: Union[RectangleObject, Tuple[float, float, float, float]],
text: str = "",
**kwargs: Any,
):
) -> None:
super().__init__(**kwargs)
self.update(
{
Expand Down Expand Up @@ -193,7 +193,7 @@ def __init__(
self,
vertices: List[Vertex],
**kwargs: Any,
):
) -> None:
super().__init__(**kwargs)
if len(vertices) == 0:
raise ValueError("A polygon needs at least 1 vertex with two coordinates")
Expand All @@ -217,7 +217,7 @@ def __init__(
*,
interior_color: Optional[str] = None,
**kwargs: Any,
):
) -> None:
if "interiour_color" in kwargs:
deprecation_with_replacement("interiour_color", "interior_color", "5.0.0")
interior_color = kwargs["interiour_color"]
Expand Down Expand Up @@ -246,7 +246,7 @@ def __init__(
highlight_color: str = "ff0000",
printing: bool = False,
**kwargs: Any,
):
) -> None:
super().__init__(**kwargs)
self.update(
{
Expand All @@ -269,7 +269,7 @@ def __init__(
*,
interior_color: Optional[str] = None,
**kwargs: Any,
):
) -> None:
if "interiour_color" in kwargs:
deprecation_with_replacement("interiour_color", "interior_color", "5.0.0")
interior_color = kwargs["interiour_color"]
Expand All @@ -295,7 +295,7 @@ def __init__(
self,
vertices: List[Tuple[float, float]],
**kwargs: Any,
):
) -> None:
super().__init__(**kwargs)
if len(vertices) == 0:
raise ValueError("A polygon needs at least 1 vertex with two coordinates")
Expand Down
4 changes: 2 additions & 2 deletions pypdf/annotations/_non_markup_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(
target_page_index: Optional[int] = None,
fit: Fit = DEFAULT_FIT,
**kwargs: Any,
):
) -> None:
super().__init__(**kwargs)
if TYPE_CHECKING:
from ..types import BorderArrayType
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(
parent: Optional[DictionaryObject] = None,
open: bool = False,
**kwargs: Any,
):
) -> None:
super().__init__(**kwargs)
self.update(
{
Expand Down
2 changes: 1 addition & 1 deletion pypdf/generic/_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Fit:
def __init__(
self, fit_type: str, fit_args: Tuple[Union[None, float, Any], ...] = ()
):
) -> None:
from ._base import FloatObject, NameObject, NullObject, NumberObject

self.fit_type = NameObject(fit_type)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ ignore = [
"A001", # Variable is shadowing a Python builtin
"A002", # Function argument is shadowing a Python builtin
"A005", # Module shadows a Python standard-library module
"ANN204", # Missing return type annotation for special method `__init__`
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
"ARG001", # Unused function argument
"ARG002", # Unused method argument
Expand Down
14 changes: 10 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import concurrent.futures
import ssl
import sys
import urllib.request
from pathlib import Path
from typing import Dict, List, Optional
from urllib.error import HTTPError

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

import yaml

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


class ReaderDummy:
def __init__(self, strict=False):
def __init__(self, strict=False) -> None:
self.strict = strict

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

def __init__(self):
def __init__(self) -> None:
self._saved_load_truncated_images = False

def __enter__(self):
def __enter__(self) -> Self:
# Allow loading incomplete images.
from PIL import ImageFile
self._saved_load_truncated_images = ImageFile.LOAD_TRUNCATED_IMAGES
ImageFile.LOAD_TRUNCATED_IMAGES = True
return self

def __exit__(self, type_, value, traceback):
def __exit__(self, type_, value, traceback) -> Optional[bool]:
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = self._saved_load_truncated_images
if type_:
Expand Down
Loading