Skip to content

Commit

Permalink
DEP: Deprecate with replacement CCITParameters (#3019)
Browse files Browse the repository at this point in the history
Deprecate CCITParameters with replacement CCITTParameters.
  • Loading branch information
j-t-1 authored Dec 25, 2024
1 parent ddc23bb commit ccdd2e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
20 changes: 17 additions & 3 deletions pypdf/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from ._utils import (
WHITESPACES_AS_BYTES,
deprecate,
deprecate_with_replacement,
deprecation_no_replacement,
logger_warning,
)
Expand Down Expand Up @@ -479,7 +480,7 @@ def decode(


@dataclass
class CCITParameters:
class CCITTParameters:
"""§7.4.6, optional parameters for the CCITTFaxDecode filter."""

K: int = 0
Expand All @@ -501,6 +502,19 @@ def group(self) -> int:
return CCITTgroup


def __create_old_class_instance(
K: int = 0,
columns: int = 0,
rows: int = 0
) -> CCITTParameters:
deprecate_with_replacement("CCITParameters", "CCITTParameters", "6.0.0")
return CCITTParameters(K, columns, rows)


# Create an alias for the old class name
CCITParameters = __create_old_class_instance


class CCITTFaxDecode:
"""
§7.4.6, CCITTFaxDecode filter (ISO 32000).
Expand All @@ -515,7 +529,7 @@ class CCITTFaxDecode:
def _get_parameters(
parameters: Union[None, ArrayObject, DictionaryObject, IndirectObject],
rows: Union[int, IndirectObject],
) -> CCITParameters:
) -> CCITTParameters:
# §7.4.6, optional parameters for the CCITTFaxDecode filter
k = 0
columns = 1728
Expand All @@ -535,7 +549,7 @@ def _get_parameters(
if CCITT.K in parameters_unwrapped:
k = parameters_unwrapped[CCITT.K].get_object() # type: ignore

return CCITParameters(K=k, columns=columns, rows=int(rows))
return CCITTParameters(K=k, columns=columns, rows=int(rows))

@staticmethod
def decode(
Expand Down
13 changes: 12 additions & 1 deletion tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ASCIIHexDecode,
CCITParameters,
CCITTFaxDecode,
CCITTParameters,
FlateDecode,
)
from pypdf.generic import ArrayObject, DictionaryObject, IndirectObject, NameObject, NumberObject
Expand Down Expand Up @@ -188,7 +189,17 @@ def test_ascii85decode_five_zero_bytes():


def test_ccitparameters():
params = CCITParameters()
with pytest.raises(
DeprecationWarning,
match="CCITParameters is deprecated and will be removed in pypdf 6.0.0. Use CCITTParameters instead",
):
params = CCITParameters()
assert params.K == 0 # zero is the default according to page 78
assert params.group == 3


def test_ccittparameters():
params = CCITTParameters()
assert params.K == 0 # zero is the default according to page 78
assert params.group == 3

Expand Down

0 comments on commit ccdd2e5

Please sign in to comment.