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-35960: Fix dataclasses.field throwing away empty metadata. #11815

Merged
merged 3 commits into from Feb 12, 2019

Conversation

Projects
None yet
7 participants
@chrahunt
Copy link
Contributor

chrahunt commented Feb 11, 2019

@@ -1737,23 +1737,25 @@ class C:
i: int = field(metadata=0)

# Make sure an empty dict works.
d = {}

This comment has been minimized.

@remilapeyre

remilapeyre Feb 11, 2019

Contributor
Suggested change Beta
d = {}
# See issue 35960
d = {}

This comment has been minimized.

@chrahunt

chrahunt Feb 12, 2019

Author Contributor

Thanks, I have addressed this in e302e24.

@dataclass
class C:
i: int = field(metadata={'test': 10, 'bar': '42', 3: 'three'})
self.assertEqual(len(fields(C)[0].metadata), 3)

This comment has been minimized.

@ericvsmith

ericvsmith Feb 11, 2019

Member

My intent with putting explicit checks for the length and values here was to ensure that if the original mapping was changed by MappingProxy, these test would detect that. I realize it's a low probability test, but I'd like to leave it in.

This comment has been minimized.

@eamanu

eamanu Feb 11, 2019

Contributor

Yes, I'd like to leave it in too.

This comment has been minimized.

@chrahunt

chrahunt Feb 12, 2019

Author Contributor

That makes sense, I have added the tests back in e302e24.

@chrahunt chrahunt force-pushed the chrahunt:fix/bpo-35960 branch from bec2bad to e302e24 Feb 12, 2019

@ericvsmith ericvsmith merged commit b01786c into python:master Feb 12, 2019

5 checks passed

Azure Pipelines PR #20190212.5 succeeded
Details
bedevere/issue-number Issue number 35960 found
Details
bedevere/news News entry found in Misc/NEWS.d
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Feb 12, 2019

Thanks @chrahunt for the PR, and @ericvsmith for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒🤖

miss-islington added a commit to miss-islington/cpython that referenced this pull request Feb 12, 2019

bpo-35960: Fix dataclasses.field throwing away empty metadata. (pytho…
…nGH-11815)

(cherry picked from commit b01786c)

Co-authored-by: Christopher Hunt <chrahunt@gmail.com>
@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Feb 12, 2019

GH-11826 is a backport of this pull request to the 3.7 branch.

ericvsmith added a commit that referenced this pull request Feb 12, 2019

bpo-35960: Fix dataclasses.field throwing away empty metadata. (GH-11815
) (GH-11826)

(cherry picked from commit b01786c)

Co-authored-by: Christopher Hunt <chrahunt@gmail.com>

@chrahunt chrahunt deleted the chrahunt:fix/bpo-35960 branch Feb 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment