Skip to content

Commit e25b882

Browse files
elazarggvanrossum
authored andcommitted
Full signature for namedtuple (#541)
1 parent 08d1069 commit e25b882

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

stdlib/2.7/collections.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# NOTE: These are incomplete!
88

99
from typing import (
10-
Any, Dict, Generic, TypeVar, Iterable, Tuple, Callable, Mapping, overload, Iterator,
10+
Any, Dict, Generic, TypeVar, Iterable, Tuple, Callable, Mapping, overload, Iterator, Type,
1111
Sized, Optional, List, Set, Sequence, Union, Reversible, MutableMapping, MutableSequence
1212
)
1313
import typing
@@ -17,7 +17,8 @@ _KT = TypeVar('_KT')
1717
_VT = TypeVar('_VT')
1818

1919
# namedtuple is special-cased in the type checker; the initializer is ignored.
20-
namedtuple = ... # type: Any
20+
def namedtuple(typename: str, field_names: Union[str, Iterable[Any]], *,
21+
verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ...
2122

2223
class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]):
2324
def __init__(self, iterable: Iterable[_T] = ...,

stdlib/2.7/typing.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Callable = object()
1515
Type = object()
1616
builtinclass = object()
1717
_promote = object()
18-
NamedTuple = object()
1918
NewType = object()
2019

2120
# Type aliases
@@ -350,3 +349,9 @@ class Pattern(Generic[AnyStr]):
350349
# Functions
351350

352351
def get_type_hints(obj: Callable) -> dict[str, Any]: ...
352+
353+
# Type constructors
354+
355+
# NamedTuple is special-cased in the type checker; the initializer is ignored.
356+
def NamedTuple(typename: str, fields: Iterable[Tuple[str, Any]], *,
357+
verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ...

stdlib/3/collections/__init__.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# These are not exported.
88
from typing import (
99
TypeVar, Iterable, Generic, Iterator, Dict, overload,
10-
Mapping, List, Tuple, Callable, Sized,
10+
Mapping, List, Tuple, Callable, Sized, Any, Type,
1111
Optional, Union
1212
)
1313
# These are exported.
@@ -25,7 +25,8 @@ _VT = TypeVar('_VT')
2525

2626

2727
# namedtuple is special-cased in the type checker; the initializer is ignored.
28-
namedtuple = object()
28+
def namedtuple(typename: str, field_names: Union[str, Iterable[Any]], *,
29+
verbose: bool = ..., rename: bool = ..., module: str = None) -> Type[tuple]: ...
2930

3031
class UserDict(MutableMapping): ...
3132
class UserList(MutableSequence): ...

stdlib/3/typing.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Callable = object()
1616
Type = object()
1717
builtinclass = object()
1818
_promote = object()
19-
NamedTuple = object()
2019
no_type_check = object()
2120
NewType = object()
2221

@@ -420,3 +419,9 @@ class Pattern(Generic[AnyStr]):
420419
# Functions
421420

422421
def get_type_hints(obj: Callable) -> dict[str, Any]: ...
422+
423+
# Type constructors
424+
425+
# NamedTuple is special-cased in the type checker; the initializer is ignored.
426+
def NamedTuple(typename: str, fields: Iterable[Tuple[str, Any]], *,
427+
verbose: bool = ..., rename: bool = ..., module: str = None) -> Type[tuple]: ...

0 commit comments

Comments
 (0)