Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def process_namedtuple(self, lvalue: NameExpr, rvalue: CallExpr) -> None:
if self._state != EMPTY:
self.add('\n')
if isinstance(rvalue.args[1], StrExpr):
items = rvalue.args[1].value.split(" ")
items = rvalue.args[1].value.replace(',', ' ').split()
Comment thread
emmatyping marked this conversation as resolved.
elif isinstance(rvalue.args[1], (ListExpr, TupleExpr)):
list_items = cast(List[StrExpr], rvalue.args[1].items)
items = [item.value for item in list_items]
Expand Down
22 changes: 22 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,28 @@ xx
[out]
from typing import Any, NamedTuple

class X(NamedTuple):
a: Any
b: Any

[case testNamedtupleAltSyntaxUsingComma]
from collections import namedtuple, xx
X = namedtuple('X', 'a, b')
xx
[out]
from typing import Any, NamedTuple

class X(NamedTuple):
a: Any
b: Any

[case testNamedtupleAltSyntaxUsingMultipleCommas]
from collections import namedtuple, xx
X = namedtuple('X', 'a,, b')
xx
[out]
from typing import Any, NamedTuple

class X(NamedTuple):
a: Any
b: Any
Expand Down