Skip to content

Two issues with subclassing namedtuple-generated class and overriding __new__ #1279

Closed
@jstasiak

Description

@jstasiak

Python 3.5.1, mypy 2f89c79.

Test code:

from typing import NamedTuple

Base = NamedTuple('Base', [('param', int)])


class Child(Base):

    def __new__(cls, param: int = 1) -> 'Child':
        return Base.__new__(cls, param)


print(Child())

Python result:

% python3 test2.py 
Child(param=1)

mypy output:

test2.py: note: In member "__new__" of class "Child":
test2.py:9: error: Too many arguments for "__new__" of "object"
test2.py: note: At top level:
test2.py:12: error: Too few arguments for "Child"

I poked around in the code a bit and I believe I managed to narrow this down to the following difference:

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions