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

Make NamedTuple provide __new__ instead of __init__ #5643

Merged
merged 3 commits into from Sep 19, 2018

Conversation

Projects
None yet
2 participants
@msullivan
Collaborator

msullivan commented Sep 19, 2018

Closes #1279.

Depends on either #5642 or a typeshed sync

@msullivan msullivan requested review from JukkaL, ilevkivskyi and gvanrossum and removed request for JukkaL Sep 19, 2018

@ilevkivskyi

Looks good, just one question about new error message that may be confusing.

@@ -587,7 +587,7 @@ class XMethBad(NamedTuple):
class MagicalFields(NamedTuple):
x: int
def __slots__(self) -> None: pass # E: Cannot overwrite NamedTuple attribute "__slots__"
def __new__(cls) -> None: pass # E: Cannot overwrite NamedTuple attribute "__new__"
def __new__(cls) -> None: pass # E: Name '__new__' already defined on line 8

This comment has been minimized.

@ilevkivskyi

ilevkivskyi Sep 19, 2018

Collaborator

This error message is not perfect but probably OK. Why don't you want to keep the old error message?

This comment has been minimized.

@msullivan

msullivan Sep 19, 2018

Collaborator

I'd prefer the old error message TBH but the interaction between the namedtuple override checks and the method actually existing seemed nontrivial and I didn't think it was worth fighting with.

This comment has been minimized.

@ilevkivskyi

ilevkivskyi Sep 19, 2018

Collaborator

If it is hard, then I think it is OK.

This comment has been minimized.

@msullivan

msullivan Sep 19, 2018

Collaborator

I looked into it a bit and it turns out to be very easy to fix as part of another PR I am putting together. I'm going to land this now with the error message regression (to avoid needing to stack this on top of the other PR, which might require more back-and-forth) and then fix the error message in that PR.

@msullivan msullivan changed the base branch from new_over_init to master Sep 19, 2018

@msullivan msullivan merged commit a88afb2 into master Sep 19, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@msullivan msullivan deleted the namedtuple-new branch Sep 19, 2018

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