-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
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.
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 |
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 error message is not perfect but probably OK. Why don't you want to keep the old error message?
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.
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.
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.
If it is hard, then I think it is 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.
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.
947c869
to
0f17104
Compare
This reverts commit 0f17104.
Closes #1279.
Depends on either #5642 or a typeshed sync