Skip to content
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

gh-124176: create_autospec must not change how dataclass defaults are mocked #124724

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 28, 2024

See #124176 (comment)
@ncoghlan found that my change introduced a behavior change (or even a regression) to dataclasses with defaults.

Before my change create_autospec would use the default's type for _spec_class.
After my change it would use the annotation's type.

Which is not always correct. For example, int | str would produce a __class__ of types.UnionType

People might rely on that, so no need to break this.

@ncoghlan
Copy link
Contributor

ncoghlan commented Oct 7, 2024

I agree with the backport labels, since we want to backport the test case, even if the functional change doesn't apply cleanly.

Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

LGTM, but I've suggested some naming clarifications for the new test cases.

Lib/test/test_unittest/testmock/testhelpers.py Outdated Show resolved Hide resolved
Lib/test/test_unittest/testmock/testhelpers.py Outdated Show resolved Hide resolved
Lib/test/test_unittest/testmock/testhelpers.py Outdated Show resolved Hide resolved
Lib/unittest/mock.py Show resolved Hide resolved
@sobolevn
Copy link
Member Author

@ncoghlan thanks a lot for the helpful suggestions! I applied all of them.

Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

Looks ready to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants