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

Rename (with deprecation) interiour_color to interior_color in classes Rectangle and Ellipse #2693

Closed
j-t-1 opened this issue May 29, 2024 · 2 comments · Fixed by #2706
Closed

Comments

@j-t-1
Copy link
Contributor

j-t-1 commented May 29, 2024

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

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
@j-t-1
Copy link
Contributor Author

j-t-1 commented Jun 7, 2024

Needed deletion of the deprecated key.

interior_color = kwargs["interiour_color"]
del kwargs["interiour_color"]

@stefan6419846
Copy link
Collaborator

This is not fixed and thus should not be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants