-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Support additional args to namedtuple() #5215
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
Changes from all commits
d394c6e
c73583d
ec25ae9
b02b21e
4613aa3
6c9a8b5
e977b71
4c47a0a
138b2fd
ebc66d2
ff63b1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,6 @@ s = b'foo' | |
from typing import TypeVar | ||
T = TypeVar(u'T') | ||
|
||
[case testNamedTupleUnicode] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This no longer worked because my stub for namedtuple just has str. Apparently we don't support |
||
from typing import NamedTuple | ||
from collections import namedtuple | ||
N = NamedTuple(u'N', [(u'x', int)]) | ||
n = namedtuple(u'n', u'x y') | ||
|
||
[builtins fixtures/dict.pyi] | ||
|
||
[case testPrintStatement] | ||
print ''() # E: "str" not callable | ||
print 1, 1() # E: "int" not callable | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ class int: | |
class str: pass | ||
class bool: pass | ||
class function: pass | ||
class ellipsis: pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was needed because a few tests that import collections didn't have |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import typing | ||
from typing import Any, Iterable, Union, Optional | ||
|
||
namedtuple = object() | ||
def namedtuple( | ||
typename: str, | ||
field_names: Union[str, Iterable[str]], | ||
*, | ||
# really bool but many tests don't have bool available | ||
rename: int = ..., | ||
module: Optional[str] = ..., | ||
defaults: Optional[Iterable[Any]] = ... | ||
) -> Any: ... |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,10 +138,6 @@ MypyFile:1( | |
from collections import namedtuple | ||
N = namedtuple('N') # E: Too few arguments for namedtuple() | ||
|
||
[case testNamedTupleWithTooManyArguments] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test stopped working because this error is now caught during type checking rather than semanal. |
||
from collections import namedtuple | ||
N = namedtuple('N', ['x'], 'y') # E: Too many arguments for namedtuple() | ||
|
||
[case testNamedTupleWithInvalidName] | ||
from collections import namedtuple | ||
N = namedtuple(1, ['x']) # E: namedtuple() expects a string literal as the first argument | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My change ends up requiring
list
to exist in all of these tests. It was easier to just change the namedtuple call than to add[builtins fixtures/list.pyi]
everywhere. I left a few with the list to make sure we test that code path.