Skip to content

Convert namedtuples to class syntax#3321

Merged
srittau merged 9 commits intopython:masterfrom
srittau:namedtuple
Oct 20, 2019
Merged

Convert namedtuples to class syntax#3321
srittau merged 9 commits intopython:masterfrom
srittau:namedtuple

Conversation

@srittau
Copy link
Collaborator

@srittau srittau commented Oct 8, 2019

No description provided.

@srittau
Copy link
Collaborator Author

srittau commented Oct 8, 2019

I don't know why pytype tests fail in files that have not been changed. Cc @rchen152

@JelleZijlstra
Copy link
Member

As Guido pointed out in the mypy issue, we need to make sure other type checkers support this syntax in stubs first.

@srittau
Copy link
Collaborator Author

srittau commented Oct 8, 2019

Missing support could be the reason why pytype fails, although the error messages are a bit weird.

@rchen152
Copy link
Collaborator

rchen152 commented Oct 8, 2019

I'll investigate the pytype failures. My first guess would be that pytype expects class Foo(NamedTuple(...)) rather than class Foo(NamedTuple): ..., hence the error message about encountering a closing parenthesis when another opening one is expected.

@srittau srittau added the status: deferred Issue or PR deferred until some precondition is fixed label Oct 9, 2019
@srittau
Copy link
Collaborator Author

srittau commented Oct 9, 2019

I have created a "deferred" label and tagged this PR with it.

rchen152 added a commit to google/pytype that referenced this pull request Oct 10, 2019
@rchen152
Copy link
Collaborator

I've changed the pytype parser to support this syntax, but our release process is a little backed up right now - I'll update again when the change is released.

rchen152 added a commit that referenced this pull request Oct 18, 2019
Yesterday's release contains a number of pyi parser fixes, such as
support for the syntax in #3321.
srittau pushed a commit that referenced this pull request Oct 18, 2019
Yesterday's release contains a number of pyi parser fixes, such as
support for the syntax in #3321.
Copy link
Member

@JelleZijlstra JelleZijlstra 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, but since both pytype and mypy had to do manual work to support this, we should also confirm that other consumers of typeshed support this syntax—pyre, PyCharm, and I think pyright.

@srittau
Copy link
Collaborator Author

srittau commented Oct 19, 2019

I just checked PyCharm, and it is supported. There is also the Microsoft language server for Visual Studio Code. Cc @mrkmndz @msfterictraut Do pyre and pyright support class-based NamedTuple syntax?

@mrkmndz
Copy link
Contributor

mrkmndz commented Oct 19, 2019

Yup that's supported in Pyre

@srittau
Copy link
Collaborator Author

srittau commented Oct 19, 2019

VSCode also supports it.

@erictraut
Copy link
Contributor

It's supported in pyright also.

@srittau srittau removed the status: deferred Issue or PR deferred until some precondition is fixed label Oct 20, 2019
@srittau
Copy link
Collaborator Author

srittau commented Oct 20, 2019

It seems to be supported by all type checkers. Merging.

@srittau srittau merged commit ec7960a into python:master Oct 20, 2019
@srittau srittau deleted the namedtuple branch October 20, 2019 08:37
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.

5 participants