Skip to content

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

Conversation

akulakov
Copy link
Contributor

@akulakov akulakov commented Sep 16, 2021

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Oct 18, 2021
Copy link
Contributor

@MaxwellDupre MaxwellDupre left a comment

Choose a reason for hiding this comment

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

tested ok.

Copy link
Contributor

@MaxwellDupre MaxwellDupre left a comment

Choose a reason for hiding this comment

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

tested ok

Comment on lines +438 to +454
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)
Copy link
Contributor

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...

Copy link
Contributor Author

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.

@cjw296
Copy link
Contributor

cjw296 commented Jun 12, 2023

Closing given @akulakov 's comment above: #28378 (comment)

@cjw296 cjw296 closed this Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants