Closed j-t-1 closed 4 weeks ago
Focusing on just the Ellipse,
In theory the interiour_color should be handled within the __init__ of the new code below.
interiour_color
__init__
In practice it gives a test error.
from .._utils import deprecate_with_replacement class Ellipse(MarkupAnnotation): def __init__( self, rect: Union[RectangleObject, Tuple[float, float, float, float]], *, interior_color: Optional[str] = None, **kwargs: Any, ): if kwargs.get("interiour_color"): interior_color = kwargs["interiour_color"] deprecate_with_replacement("interiour_color", "interior_color", "6.0.0") super().__init__(**kwargs) self.update( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Circle"), NameObject("/Rect"): RectangleObject(rect), } ) if interior_color: self[NameObject("/IC")] = ArrayObject( [FloatObject(n) for n in hex_to_rgb(interior_color)] )
> > =================================== FAILURES =================================== > ________________________ test_annotation_builder_circle ________________________ > [gw3] linux -- Python 3.7.17 /opt/hostedtoolcache/Python/3.7.17/x64/bin/python > > pdf_file_path = PosixPath('/tmp/pytest-of-runner/pytest-0/popen-gw3/pypdf-data0/a08eb014-95d8-43ff-ba17-8e9de9eb08b6.pdf') > > def test_annotation_builder_circle(pdf_file_path): > # Arrange > pdf_path = RESOURCE_ROOT / "crazyones.pdf" > reader = PdfReader(pdf_path) > page = reader.pages[0] > writer = PdfWriter() > writer.add_page(page) > > # Act > with pytest.warns(DeprecationWarning): > circle_annotation = AnnotationBuilder.ellipse( > > rect=(50, 550, 200, 650), interiour_color="ff0000" > ) > > tests/test_generic.py:947: > > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > pypdf/generic/__init__.py:362: in ellipse > return Ellipse(rect=rect, interiour_color=interiour_color) > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > > self = {}, rect = (50, 550, 200, 650), interior_color = 'ff0000' > kwargs = {'interiour_color': 'ff0000'} > > def __init__( > self, > rect: Union[RectangleObject, Tuple[float, float, float, float]], > *, > interior_color: Optional[str] = None, > **kwargs: Any, > ): > if kwargs.get("interiour_color"): > interior_color = kwargs["interiour_color"] > deprecate_with_replacement("interiour_color", "interior_color", "6.0.0") > > super().__init__(**kwargs) > E TypeError: __init__() got an unexpected keyword argument 'interiour_color' > > pypdf/annotations/_markup_annotations.py:267: TypeError
Needed deletion of the deprecated key.
interior_color = kwargs["interiour_color"] del kwargs["interiour_color"]
This is not fixed and thus should not be closed.
Explanation
Focusing on just the Ellipse,
In theory the
interiour_color
should be handled within the__init__
of the new code below.In practice it gives a test error.
Code Example