Skip to content

MAINT: don't format logs in log call.#25073

Merged
jklymak merged 2 commits into
matplotlib:mainfrom
Carreau:log-f
Jan 25, 2023
Merged

MAINT: don't format logs in log call.#25073
jklymak merged 2 commits into
matplotlib:mainfrom
Carreau:log-f

Conversation

@Carreau

@Carreau Carreau commented Jan 25, 2023

Copy link
Copy Markdown
Contributor

In particular f-string:

There are many reason not to use f-string in logs,

But also % formatting in a couple of places.

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

In particular f-string:

There are many reason not to use f-string in logs,
 - F-strings are eager, so might be slow. So this may affect performance
   (we can filter before formatting).
 - prevent structured logging or handler to highlight.
 - Security (untrusted input can lead to DOS on formatting, https://discuss.python.org/t/safer-logging-methods-for-f-strings-and-new-style-formatting/13802)

But also % formatting in a couple of places.
Comment thread lib/matplotlib/_mathtext.py Outdated
Co-authored-by: Elliott Sales de Andrade <[email protected]>
@story645

Copy link
Copy Markdown
Member

Can a note about this be put somewhere on the contributing code page? I worry that this is the type of thing that will get changed in either direction 16 times.

@jklymak jklymak merged commit aaf01bf into matplotlib:main Jan 25, 2023
@jklymak

jklymak commented Jan 25, 2023

Copy link
Copy Markdown
Member

@meeseeksdev backport to 3.7.0

@jklymak jklymak added this to the v3.7.0 milestone Jan 25, 2023
@lumberbot-app

lumberbot-app Bot commented Jan 25, 2023

Copy link
Copy Markdown

Something went wrong ... Please have a look at my logs.

It seems that the branch you are trying to backport to does not exist.

@jklymak

jklymak commented Jan 25, 2023

Copy link
Copy Markdown
Member

@meeseeksdev backport to 3.7.x

@lumberbot-app

lumberbot-app Bot commented Jan 25, 2023

Copy link
Copy Markdown

Something went wrong ... Please have a look at my logs.

It seems that the branch you are trying to backport to does not exist.

@jklymak

jklymak commented Jan 25, 2023

Copy link
Copy Markdown
Member

@meeseeksdev backport to v3.7.x

@lumberbot-app

lumberbot-app Bot commented Jan 25, 2023

Copy link
Copy Markdown

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.7.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 aaf01bf0918d6d072a9824581aa3e5bccf1ad7e0
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am "Backport PR #25073: MAINT: don't format logs in log call."
  1. Push to a named branch:
git push YOURFORK v3.7.x:auto-backport-of-pr-25073-on-v3.7.x
  1. Create a PR against branch v3.7.x, I would have named this PR:

"Backport PR #25073 on branch v3.7.x (MAINT: don't format logs in log call.)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@jklymak

jklymak commented Jan 25, 2023

Copy link
Copy Markdown
Member

@Carreau is this important enough to manually backport?

@ksunden

ksunden commented Jan 25, 2023

Copy link
Copy Markdown
Member

I didn't go back to find these lines specifically, but most of these are likely made into f strings via #24980 which was not itself backported to 3.7.x

@jklymak

jklymak commented Jan 25, 2023

Copy link
Copy Markdown
Member

Ah.... It did all seem too obscure to have triggered conflicts. So I think this can safely not be backported.

@greglucas

Copy link
Copy Markdown
Contributor

This may conflict with the f-string PR, but that PR only changed from .format() to f"{}" in the log calls, so we were already previously doing it poorly with the str.format(val). This is an improvement and uses the logger formatting, not str % val but rather log(str, val). I don't think it would be super hard to manually backport if @Carreau wants to tackle it.

@tacaswell

Copy link
Copy Markdown
Member

Given it was non ideal before (and probably has been for a while) I do not think backporting is a high-priority.

@Carreau

Carreau commented Jan 25, 2023

Copy link
Copy Markdown
Contributor Author

I agree it's not critical to backport.

It can be put on the style guide, there is also a pylint item that detect some of those usage.
But again I don't think it is critical.

Mostly it's giving the right example, so it has more chances of not being copy/pasted somewhere else.

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 this pull request may close these issues.

7 participants