Skip to content

Error type checking nested namedtuples #15061

Closed
@hmc-cs-mdrissi

Description

@hmc-cs-mdrissi

Bug Report

from typing import NamedTuple

class RaggedFeature(NamedTuple):
  class RowSplits(NamedTuple):
    x: int

  splits: RowSplits

produces an error message of,

Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]"
Expected Behavior

No error. I ran into this writing stubs for real code from here that does use nested namedtuples at runtime. It also type checks fine in pyright. Minor though as type: ignore seems to work fine for it in typeshed.

Your Environment

Latest mypy version 1.2. Default flags/configuration is enough.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions