Skip to content

namedtuple with cls in field names gives type warnings #3184

@hoxbro

Description

@hoxbro

Summary

The following will give multiple type warnings. Also seeing it on pyrefly but not with mypy or pyright.

from collections import namedtuple

PInfo = namedtuple("PInfo", "inst cls")
PInfo(None, str)  # works
PInfo(inst=None, cls=str)  # problem
No argument provided for required parameter `cls` (missing-argument) [Ln 5, Col 1]
Multiple values provided for parameter `cls` (parameter-already-assigned) [Ln 5, Col 18]
Argument is incorrect: Argument type `str` does not satisfy upper bound `PInfo` of type variable `Self` (invalid-argument-type) [Ln 5, Col 18]
Argument is incorrect: Expected `type[PInfo]`, found `<class 'str'>` (invalid-argument-type) [Ln 5, Col 18]

https://play.ty.dev/93b9b1e5-98bc-4a5d-aa74-04a72a52780e

Version

ty 0.0.26

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions