From c2bc939cb5d5a31edfb8c362c5b2ba03ed5930b7 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Thu, 25 Apr 2024 19:04:29 +0200 Subject: [PATCH] Add a deprecation warning for version and identifier in __init__ This new code is a bit more compatible with previous versions, and should at least work with older versions of WeasyPrint. --- pydyf/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pydyf/__init__.py b/pydyf/__init__.py index 30a718e..0f98780 100755 --- a/pydyf/__init__.py +++ b/pydyf/__init__.py @@ -9,6 +9,7 @@ from codecs import BOM_UTF16_BE from hashlib import md5 from math import ceil, log +from warnings import warn VERSION = __version__ = '0.9.0' @@ -443,8 +444,17 @@ def data(self): class PDF: """PDF document.""" - def __init__(self): + def __init__(self, version=None, identifier=None): """Create a PDF document.""" + if version or identifier: # to be removed in next version + warn( + "PDF objects don’t take version or identifier during initialization " + "anymore. These properties are now stored but ignored, and will be " + "removed and rejected in next version of pydyf. Please pass these " + "properties to the PDF.write() method instead.", DeprecationWarning) + self.version = _to_bytes(version) if version else b'1.7' # to be removed + self.identifier = identifier # to be removed + #: Python :obj:`list` containing the PDF’s objects. self.objects = []