-
Notifications
You must be signed in to change notification settings - Fork 264
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
Get rid of FPDF class/instance attributes getting passed to HTML2PDF. #1198
Comments
Yes, I made that commit! 😅
The intent was to avoid repeatedly passing the same arguments to
In restropect, you are probably right 🙂 Other thoughts:
class PDF(FPDF):
def write_html(self, text, *args, **kwargs):
super().write_html(text, *args, table_line_separators=True, warn_on_tags_not_matching=True, **kwargs) |
Packing them in a dict and supplying that with
This is not actually documented in any way, not even in the docstring. I doubt that anyone other than you (and now @lcgeneralprojects) has ever used it. End users relying on entirely undocumented "features" live risky to begin with. |
Agreed! We should just not forget to mention this change in the |
Whilst I do not disagree with the sentiment.
I would not be suprised, I at least have been using this.
|
What you're doing there is one of the suggested alternatives, and perfectly fine. The "feature" we're about to eliminate won't affect you at all. |
Problem
While writing tests for #1170 , @lcgeneralprojects has stumbled across a rather obscure and dubious "feature" of
write_html()
.Apparently since release 2.4.2, added in this commit, it is possible to feed
write_html()
keyword arguments by adding class or instance attributes toFPDF()
itself before calling the method.At a time where
write_html()
only had two or three arguments, this may have looked like a good idea, but polluting the namespace of class A in order to feed initialization arguments to class B doesn't seem desirable to me under any circumstances. I'm also unable to imagine a use case where this would be more practical than simply passing those arguments directly, or to keep them in a dictionary if they need to be collected first.Solution
Let's get rid of this "feature".
Fpdf2 is getting increasingly complex, and we really need to try hard to keep the namespaces of our various modules as clean as possible. Encouraging users to cross-pollute those namespaces is simply bad design. Without any documentation (and even if it was documented), there's also a risk that a user subclassing
FPDF()
and adding their own attributes might inadvertedly cause changes in the behaviour ofwrite_html()
.Additional context
Other than the commit message "made <li> bullets & indentation configurable through class attributes, instance attributes or optional method arguments", I can find no documentation at all about how this is supposed to be used, and why it would be useful.
The text was updated successfully, but these errors were encountered: