Skip to content
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

inner class of NamedTuple triggers "Invalid statement" #10337

Open
Lambda-Logan opened this issue Apr 17, 2021 · 2 comments
Open

inner class of NamedTuple triggers "Invalid statement" #10337

Lambda-Logan opened this issue Apr 17, 2021 · 2 comments
Labels
bug mypy got something wrong topic-named-tuple

Comments

@Lambda-Logan
Copy link

Lambda-Logan commented Apr 17, 2021

This will show an error.

from typing import NamedTuple


class Name(NamedTuple):
    name: str = ""

    class Inner:
        pass

>>> error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]"

However, this works fine:

class Name:
    name: str = ""

    class Inner:
        pass

mypy 0.761
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux

@Lambda-Logan Lambda-Logan added the bug mypy got something wrong label Apr 17, 2021
@Akuli
Copy link
Contributor

Akuli commented Apr 19, 2021

Are you sure this is a bug? The NamedTuple docs say "docstrings and methods", without a mention of nested classes.

@JelleZijlstra
Copy link
Member

At runtime it does work in 3.9, but in 3.6 the inner class just disappears. I'm not sure that's on purpose. I added runtime support for NamedTuple methods in 3.6 I believe, but perhaps a change since then made nested classes also work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-named-tuple
Projects
None yet
Development

No branches or pull requests

4 participants