-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-127805: Clarify Formatter initialization in logging.rst #127850
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM.
cc @picnixz for a second look.
Thank you @picnixz @ZeroIntensity for reviewing PR! If everything looks good, please proceed with merging it. |
Neither of us have merge permissions, we're triagers (though Bénédikt might soon)! You'll have to wait for a core dev to get to this. |
Thank you for clarifying, @ZeroIntensity! I apologize for the oversight, as I’m still new to Python and the contribution process. |
The wording of the change might imply that the instance has to be one of the |
Well... even if it's an instance of a subclass, |
Thank you, @vsajip and @picnixz, for the feedback! @jlynchMicron, who created the issue, reviewed the PR and confirmed that the changes are correct in their comment. The current wording is meant to make it clear that the formatter argument must be an initialized instance of Formatter or a subclass. I agree that it might sound like only Formatter is allowed, which could be confusing. Would it help if I updated the wording to say something like "an initialized instance of Formatter or one of its subclasses"? Let me know, and I can make the changes to avoid any misunderstanding. |
Yes, but we're talking about just a documentation change. For example, I think the existing text (mentioning
Yes, I think it would. |
Ok, I see your point. To be consistent, should we also update the |
I guess we could. But let's think about this - do we really want to go through the documentation checking for all instances of where a class is mentioned, meaning that an instance is required, and updating all cases in case they might be misunderstood? The usual way to interpret when you say "pass in a Formatter" is to infer that an instance is to be passed, and and not the But then someone might say "it's not really clear that Sometimes the problem is the documentation, but sometimes it's reader comprehension (bearing in mind different people have different mother tongues, different levels of experience as developers, etc). Whatever the documentation says, there will be some readers who can misinterpret it - IMO one can only go so far in accommodating all such cases. |
Yes, I agree with the points you raised. I think it's important to keep things clear from our side, but also acknowledge that there's a limit to how much we can accommodate every potential misinterpretation. That said, if you have any suggestions for additional documentation or clarifications that could make the intent absolutely clear, we can certainly consider them. Otherwise, we can close the issue if we believe it's a matter of reader comprehension. |
While I agree with the point that the usual interpretation of "pass in a Formatter" implies an instance rather than the class itself, the fact that this issue was raised indicates some level of confusion among readers, which suggests that clarifying it in the documentation could be helpful. However, we don't need to go through every API documentation and update it proactively; if users face issues, they can raise them, and we can address them like this issue. @vsajip Could you please let me know your thoughts on this or what steps you'd recommend to take next? |
Just to chime in here as the person that originally raised the issue; maybe it's just me, but I have written a lot of funky python code that has functions that takes in uninitialized classes as function arguments. I think this sort of thing happens more in the data conditioning and database ORM space where dataclasses are used as formats/templates for data conditioning (which is kinda what a Formatter class does). So that being said, I could be in the minority when reading documentation that says pass in a class and not immediately think to instantiate that class first. The error generated from using the format function of an un-instantiated Formatter is sort of non-intuitive until you realize that the "record" argument is being passed in as "self". This issue was an attempt to possibly address that confusion for others. |
@jlynchMicron @vsajip Taking everyone’s feedback into account, I understand that the API has been stable for years and that the usual interpretation of “pass in a Formatter” inherently implies an instance rather than the class itself. However, given that the issue was raised—alongside @jlynchMicron’s experience—it does suggest that there might be room for confusion for some readers. The proposed wording update to "an initialized instance of Formatter or one of its subclasses" aims to clarify the intent without adding unnecessary verbosity. That said, I’d like to confirm: would you recommend proceeding with this wording change for clarity, extending it to setFilter for consistency as suggested by @picnixz, or do you think the issue and PR could be closed altogether, considering your points on reader comprehension and the longstanding clarity of the API? I’ll proceed based on your final recommendation. |
The confusion might arise from the fact that we refer to "Formatter" which leads to the Formatter class by saying "Sets the Formatter [...]". How about rephrasing it as Sets the formatter object for this handler to *fmt*. The *fmt* argument
must be a :class:`Formatter` instance or ``None``. I feel that mentioning subclasses or "initialized" would be overly verbose. While I see the distinction with "initialized" (through Concerning An alternative to changing the wording is to refer to some examples, without changing the current wording. From there, it would become clearer what we expect right? |
I too think of it as the correct approach. Shall I update the PR with this change? |
Clarified that the fmt argument in Handler.setFormatter must be an initialized Formatter instance in the logging.rst documentation.
Issue:
Resolves #127805
📚 Documentation preview 📚: https://cpython-previews--127850.org.readthedocs.build/en/127850/library/logging.html#logging.Handler.setFormatter