KEMBAR78
Adds better NamedTuple error messages by sobolevn · Pull Request #11127 · python/mypy · GitHub
Skip to content

Conversation

sobolevn
Copy link
Member

While working on #11047 I've noticed that mypy reports the same error for both collection.namedtuple() and typing.NamedTuple().

I've tried to fix to report the correct name.

from collections import namedtuple

X = namedtuple('X', 'x, _y, _z') # E: namedtuple() field names cannot start with an underscore: _y, _z
X = namedtuple('X', 'x, _y, _z') # E: "namedtuple()" field names cannot start with an underscore: _y, _z
Copy link
Member

Choose a reason for hiding this comment

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

Why did you add the extra quotes? They feel unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Most of the time mypy highlights the most important code part with "", this feels more similar to other cases. For example, here's how it renders in my terminal (with / without ""):
Снимок экрана 2021-09-18 в 1 20 34

In my opinion, the first one looks and reads better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The double quotes look reasonable to me. Previously we didn't use them probably because the () suffix makes it look like code, it seems okay to add them.

Copy link
Collaborator

@JukkaL JukkaL left a 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 style nit (optional).

@JukkaL JukkaL merged commit 96d7242 into python:master Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants