-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
bpo-45215: In Mock class, deprecate invalid name parent args and expand docs #28378
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
bpo-45215: In Mock class, deprecate invalid name parent args and expand docs #28378
Conversation
|
This PR is stale because it has been open for 30 days with no activity. |
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.
tested ok.
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.
tested ok
| warnings.warn('parent argument should be a Mock instance', | ||
| DeprecationWarning, stacklevel=stacklevel) | ||
|
|
||
| if name is not None and not isinstance(name, str): | ||
| import warnings | ||
| if isinstance(self, NonCallableMagicMock): | ||
| stacklevel = 3 | ||
| elif isinstance(self, MagicMock): | ||
| stacklevel = 4 | ||
| elif isinstance(self, Mock): | ||
| stacklevel = 3 | ||
| elif isinstance(self, NonCallableMock): | ||
| stacklevel = 2 | ||
| else: | ||
| stacklevel = 1 | ||
| warnings.warn('name argument should be a string', | ||
| DeprecationWarning, stacklevel=stacklevel) |
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.
Why are these deprecation warnings rather than just exceptions?
I don't find warnings like this helpful, as the behaviour here is unlikely to ever be changed...
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.
This would be a backwards incompatible change with exceptions. Right now, using non-string arg is fine if you don't display the mock obj.
That said, I think this probably shouldn't be merged because it doesn't seem like people are running into this issue, as it was created a while ago and nobody else commented on it.
If you agree, we can close this issue and MR.
|
Closing given @akulakov 's comment above: #28378 (comment) |
https://bugs.python.org/issue45215