From 2360165e2cea18aae0856167e3549ba1bcf846d0 Mon Sep 17 00:00:00 2001 From: geisserml Date: Fri, 5 Apr 2024 00:14:15 +0200 Subject: [PATCH] Expand constructor assignments This is longer, but cleaner. Imagine you have to edit it and assignment order gets wrong :P BTW, normalize PdfFormEnv constructor param order. --- src/pypdfium2/_helpers/attachment.py | 3 ++- src/pypdfium2/_helpers/document.py | 18 ++++++++++++------ src/pypdfium2/_helpers/matrix.py | 3 --- src/pypdfium2/_helpers/page.py | 4 +++- src/pypdfium2/_helpers/pageobjects.py | 5 ++++- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/pypdfium2/_helpers/attachment.py b/src/pypdfium2/_helpers/attachment.py index 5b69e62b6..ef5f45457 100644 --- a/src/pypdfium2/_helpers/attachment.py +++ b/src/pypdfium2/_helpers/attachment.py @@ -36,7 +36,8 @@ class PdfAttachment (pdfium_i.AutoCastable): def __init__(self, raw, pdf): - self.raw, self.pdf = raw, pdf + self.raw = raw + self.pdf = pdf def get_name(self): diff --git a/src/pypdfium2/_helpers/document.py b/src/pypdfium2/_helpers/document.py index 81eed78f3..75ef2ef90 100644 --- a/src/pypdfium2/_helpers/document.py +++ b/src/pypdfium2/_helpers/document.py @@ -172,7 +172,7 @@ def init_forms(self, config=None): raw = pdfium_c.FPDFDOC_InitFormFillEnvironment(self, config) if not raw: raise PdfiumError(f"Initializing form env failed for document {self}.") - self.formenv = PdfFormEnv(raw, config, self) + self.formenv = PdfFormEnv(raw, self, config) self._add_kid(self.formenv) if formtype in (pdfium_c.FORMTYPE_XFA_FULL, pdfium_c.FORMTYPE_XFA_FOREGROUND): @@ -543,8 +543,10 @@ class PdfFormEnv (pdfium_i.AutoCloseable): Parent document this form env belongs to. """ - def __init__(self, raw, config, pdf): - self.raw, self.config, self.pdf = raw, config, pdf + def __init__(self, raw, pdf, config): + self.raw = raw + self.pdf = pdf + self.config = config super().__init__(PdfFormEnv._close_impl, self.config, self.pdf) @property @@ -568,7 +570,8 @@ class PdfXObject (pdfium_i.AutoCloseable): """ def __init__(self, raw, pdf): - self.raw, self.pdf = raw, pdf + self.raw = raw + self.pdf = pdf super().__init__(pdfium_c.FPDF_CloseXObject) @property @@ -629,7 +632,9 @@ class PdfBookmark (pdfium_i.AutoCastable): """ def __init__(self, raw, pdf, level): - self.raw, self.pdf, self.level = raw, pdf, level + self.raw = raw + self.pdf = pdf + self.level = level def get_title(self): """ @@ -670,7 +675,8 @@ class PdfDest (pdfium_i.AutoCastable): """ def __init__(self, raw, pdf): - self.raw, self.pdf = raw, pdf + self.raw = raw + self.pdf = pdf def get_index(self): """ diff --git a/src/pypdfium2/_helpers/matrix.py b/src/pypdfium2/_helpers/matrix.py index 4d9aff402..a8cab515d 100644 --- a/src/pypdfium2/_helpers/matrix.py +++ b/src/pypdfium2/_helpers/matrix.py @@ -40,17 +40,14 @@ class PdfMatrix: def __init__(self, a=1, b=0, c=0, d=1, e=0, f=0): self.a, self.b, self.c, self.d, self.e, self.f = a, b, c, d, e, f - def __repr__(self): return f"PdfMatrix{self.get()}" - def __eq__(self, other): if type(self) is not type(other): return False return (self.get() == other.get()) - @property def _as_parameter_(self): return ctypes.byref( self.to_raw() ) diff --git a/src/pypdfium2/_helpers/page.py b/src/pypdfium2/_helpers/page.py index f536b6e5b..e0dd5d42c 100644 --- a/src/pypdfium2/_helpers/page.py +++ b/src/pypdfium2/_helpers/page.py @@ -27,7 +27,9 @@ class PdfPage (pdfium_i.AutoCloseable): """ def __init__(self, raw, pdf, formenv): - self.raw, self.pdf, self.formenv = raw, pdf, formenv + self.raw = raw + self.pdf = pdf + self.formenv = formenv super().__init__(PdfPage._close_impl, self.formenv) diff --git a/src/pypdfium2/_helpers/pageobjects.py b/src/pypdfium2/_helpers/pageobjects.py index 0d712fec3..e83bbf5c7 100644 --- a/src/pypdfium2/_helpers/pageobjects.py +++ b/src/pypdfium2/_helpers/pageobjects.py @@ -55,7 +55,10 @@ def __new__(cls, raw, *args, **kwargs): def __init__(self, raw, page=None, pdf=None, level=0): - self.raw, self.page, self.pdf, self.level = raw, page, pdf, level + self.raw = raw + self.page = page + self.pdf = pdf + self.level = level if page is not None: if self.pdf is None: