-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-41403: Improve error message for invalid mock target #30833
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
Conversation
Lib/unittest/mock.py
Outdated
raise TypeError("Need a valid target to patch. You supplied: %r" % | ||
(target,)) |
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.
raise TypeError("Need a valid target to patch. You supplied: %r" % | |
(target,)) | |
raise TypeError(f"Need a valid target to patch. You supplied: {target}") |
since there is a change of nearby lines anyway. Plus, "b'%r' is deprecated, but will not be removed during the 3.x series" in the docs.
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.
Should be {target!r}
I suppose?
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.
Ah, yes. I was optimistic seeing string-only nature of target
:
Line 1693 in 461e59e
`target` should be a string in the form `'package.module.ClassName'`. The |
Like, once it was an object requiring some special formatting but now it's just a string. However, I forgot that %r
additionally escapes non-ascii code points.
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.
Right, also this bpo is about the case where the error is that you passed in some non-string object.
Thanks @iritkatriel for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
Sorry @iritkatriel, I had trouble checking out the |
Sorry, @iritkatriel, I could not cleanly backport this to |
GH-30834 is a backport of this pull request to the 3.10 branch. |
GH-30835 is a backport of this pull request to the 3.9 branch. |
|
|
) (pythonGH-30835) (cherry picked from commit f7955a8)
https://bugs.python.org/issue41403