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

Unexpected arguments type error #8651

Open
eupraxis1981 opened this issue Apr 9, 2020 · 4 comments
Open

Unexpected arguments type error #8651

eupraxis1981 opened this issue Apr 9, 2020 · 4 comments
Labels
false-positive mypy gave an error on correct code feature priority-2-low

Comments

@eupraxis1981
Copy link

Below code provides example:

MergeStrategy = NamedTuple(
typename="MergeStrategy",
fields=[("left", str), ("right", str), ("how", str), ("on", List[str])],
)
Generates error
{
"resource": <>,
"owner": "python",
"code": "error",
"severity": 8,
"message": "Unexpected arguments to namedtuple()",
"source": "mypy",
"startLineNumber": 53,
"startColumn": 18,
"endLineNumber": 53,
"endColumn": 18
}

whereas this does not:
MergeStrategy = NamedTuple(
"MergeStrategy", [("left", str), ("right", str), ("how", str), ("on", List[str])],
)

Same thing for regular namedtuple.

get same error with this:
MergeStrategy = namedtuple(typename="MergeStrategy", field_names=["left", "right", "how", "on"])

but this is fine:
MergeStrategy = namedtuple("MergeStrategy", ["left", "right", "how", "on"])

@hauntsaninja
Copy link
Collaborator

Shouldn't be too hard to fix, look at parse_namedtuple_args in semanal_namedtuple.py. Not sure if mypy's AST has the equivalent of inspect.Signature.bind, but that would make it really easy.

@JukkaL JukkaL added false-positive mypy gave an error on correct code feature priority-2-low labels Apr 9, 2020
@momohatt
Copy link
Contributor

momohatt commented Oct 4, 2020

I was investigating this issue and noticed that the keyword arguments typename and fields are deprecated for typing.NamedTuple (python/cpython#16222)

It seems that these keyword arguments are still allowed for the regular namedtuple, though.

@gvanrossum
Copy link
Member

More than deprecated -- typing.NamedTuple now markes these as positional args only. But collections.namedtuple is unchanged. Not sure if there's anything actionable left here?

@momohatt
Copy link
Contributor

Yes, I'm not sure if mypy should support these keyword arguments for collections.namedtuple when typing.NamedTuple doesn't accept it...
Still, it might be a good idea to elaborate the error message like: error: mypy does not support keyword arguments 'typename' and 'field_names' for namedtuple()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive mypy gave an error on correct code feature priority-2-low
Projects
None yet
Development

No branches or pull requests

5 participants