-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
MNT: improve error messages on bad pdf metadata input #17935
Conversation
d2be6c2
to
1970ce3
Compare
I simplified the setup a little, and added tests. |
1970ce3
to
d05d9b3
Compare
d05d9b3
to
6528697
Compare
@@ -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""" |
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.
10000"""an instance of str""" | |
"""Return whether *x* is an instance of ``str``.""" |
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.
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.
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.
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.
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.
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""" |
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.
"""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"}""" |
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.
"""one of {"True", "False", "Unknown"}""" | |
"""Return whether *x* is one of {"True", "False", "Unknown"}.""" |
Tell the user what keys and types are expected.
6528697
to
b187215
Compare
@@ -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""" |
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.
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"
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