Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
iritkatriel commented Jan 23, 2022 • edited by bedevere-bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-bot
Uh oh!
There was an error while loading. Please reload this page.
Lib/unittest/mock.py Outdated
| raiseTypeError("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.
| raiseTypeError("Need a valid target to patch. You supplied: %r"% | |
| (target,)) | |
| raiseTypeError(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.
miss-islington commented Jan 23, 2022
Thanks @iritkatriel for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
miss-islington commented Jan 23, 2022
Sorry @iritkatriel, I had trouble checking out the |
miss-islington commented Jan 23, 2022
Sorry, @iritkatriel, I could not cleanly backport this to |
bedevere-bot commented Jan 23, 2022
GH-30834 is a backport of this pull request to the 3.10 branch. |
bedevere-bot commented Jan 23, 2022
GH-30835 is a backport of this pull request to the 3.9 branch. |
bedevere-bot commented Jan 23, 2022
|
bedevere-bot commented Jan 23, 2022
|
) (pythonGH-30835) (cherry picked from commit f7955a8)
https://bugs.python.org/issue41403