Skip to content

NamedTuple with no fields causes "object" not callable error #1276

Closed

Description

@averagehat
Blue = NamedTuple("Blue", [])

Fails with:

example.py:5: error: "object" not callable

But this code runs fine in python2/python3.

Edit:
Seems like it's falling out to here
a bit odd to me because NamedTuple does indeed have a __call__ attribute

Interesting. The following fails:

alist = [('afield', str)]
Green = NamedTuple("Green", alist)

example.py:3: error: List literal expected as the second argument to namedtuple()
example.py:3: error: "object" not callable

But this works:

Green = NamedTuple("Green", [('afields', str)])

I think the type_map is storing NameExpr(NamedTuple [typing.NamedTuple]) as an object, and it looks like the in the latter case it's skipping a check . . . I remember reading in an issue that NamedTuple wasn't fully supported, so I assume that's what's going on.

Activity

  1. gvanrossum commented on Mar 6, 2016

    @gvanrossum
    Member

    I think I know what this is. Because there are no items, the code here thinks there's an error. It then skips the assignment to call.analyzed a few lines later. Maybe it can be fixed by changing "return" to "info =" in the error branch.

  2. gvanrossum commented on Mar 6, 2016

    @gvanrossum
    Member

    FWIW the thing you noted with using a variable for the list of fields is unrelated -- it's a general thing that mypy doesn't understand dynamically constructed types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions