8000 MNT: improve error messages on bad pdf metadata input by tacaswell · Pull Request #17935 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

MNT: improve error messages on bad pdf metadata input #17935

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

Merged

Conversation

tacaswell
Copy link
Member
@tacaswell tacaswell commented Jul 15, 2020

PR Summary

Tell the user what keys and types are expected.

This still needs tests. Happy if anyone wants to adopt the PR and finish it.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant

@tacaswell tacaswell added Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! status: has patch patch suggested, PR still needed labels Jul 15, 2020
@tacaswell tacaswell added this to the v3.4.0 milestone Jul 15, 2020
@QuLogic QuLogic force-pushed the mnt_better_warning_on_pdfmetadata branch from d2be6c2 to 1970ce3 Compare September 11, 2020 07:27
@QuLogic QuLogic removed status: needs tests status: has patch patch suggested, PR still needed labels Sep 11, 2020
@QuLogic QuLogic marked this pull request as ready for review September 11, 2020 07:27
@QuLogic
Copy link
Member
QuLogic commented Sep 11, 2020

I simplified the setup a little, and added tests.

@QuLogic QuLogic force-pushed the mnt_better_warning_on_pdfmetadata branch from 1970ce3 to d05d9b3 Compare September 11, 2020 23:56
@QuLogic QuLogic force-pushed the mnt_better_warning_on_pdfmetadata branch from d05d9b3 to 6528697 Compare September 11, 2020 23:59
@@ -183,12 +183,15 @@ def _create_pdf_info_dict(backend, metadata):
info = {k: v for (k, v) in info.items() if v is not None}

def is_string_like(x):
"""an instance of str"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10000
Suggested change
"""an instance of str"""
"""Return whether *x* is an instance of ``str``."""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the point of the docstring is to be used in the error message. It's a nested function in a private method, so is not otherwise user-facing.

Copy link
Member
@timhoffm timhoffm Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! In that case, please add a comment below the docstring. Otherwise somebody will "clean" this up later. I'm also wondering why flake8-docstrings is not complaining about the non-compliant docstring format.

Alternatively, It may be better to add the text explicitly to the keywords mapping alongside the checking function than misusing the docstring. Or add an extra attribute to the functions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, using the docstring as a message is too clever.

We should instead use an explicit attribute.

def is_string_like(x):
    return isinstance(x, str)
is_string_like.expected_value = "an instance of str"

return isinstance(x, str)

def is_date(x):
"""an instance of datetime.datetime"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""an instance of datetime.datetime"""
"""Return whether *x* is an instance of ``datetime.datetime``."""

return isinstance(x, datetime)

def check_trapped(x):
"""one of {"True", "False", "Unknown"}"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""one of {"True", "False", "Unknown"}"""
"""Return whether *x* is one of {"True", "False", "Unknown"}."""

@QuLogic QuLogic force-pushed the mnt_better_warning_on_pdfmetadata branch from 6528697 to b187215 Compare September 22, 2020 19:34
@@ -183,12 +183,15 @@ def _create_pdf_info_dict(backend, metadata):
info = {k: v for (k, v) in info.items() if v is not None}

def is_string_like(x):
"""an instance of str"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, using the docstring as a message is too clever.

We should instead use an explicit attribute.

def is_string_like(x):
    return isinstance(x, str)
is_string_like.expected_value = "an instance of str"

@tacaswell tacaswell requested a review from timhoffm September 23, 2020 15:16
@timhoffm timhoffm merged commit 1dcfce6 into matplotlib:master Sep 23, 2020
@tacaswell tacaswell deleted the mnt_better_warning_on_pdfmetadata branch May 6, 2021 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: pdf Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0