Skip to content

Full signature for namedtuple #541

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

Merged
merged 9 commits into from
Sep 13, 2016
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
5 changes: 3 additions & 2 deletions stdlib/2.7/collections.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# NOTE: These are incomplete!

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

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

class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]):
def __init__(self, iterable: Iterable[_T] = ...,
Expand Down
7 changes: 6 additions & 1 deletion stdlib/2.7/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Callable = object()
Type = object()
builtinclass = object()
_promote = object()
NamedTuple = object()
NewType = object()

# Type aliases
Expand Down Expand Up @@ -348,3 +347,9 @@ class Pattern(Generic[AnyStr]):
# Functions

def get_type_hints(obj: Callable) -> dict[str, Any]: ...

# Type constructors

# NamedTuple is special-cased in the type checker; the initializer is ignored.
def NamedTuple(typename: str, fields: Iterable[Tuple[str, Any]], *,
verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ...
5 changes: 3 additions & 2 deletions stdlib/3/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# These are not exported.
from typing import (
TypeVar, Iterable, Generic, Iterator, Dict, overload,
Mapping, List, Tuple, Callable, Sized,
Mapping, List, Tuple, Callable, Sized, Any, Type,
Optional, Union
)
# These are exported.
Expand All @@ -25,7 +25,8 @@ _VT = TypeVar('_VT')


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

class UserDict(MutableMapping): ...
class UserList(MutableSequence): ...
Expand Down
7 changes: 6 additions & 1 deletion stdlib/3/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Callable = object()
Type = object()
builtinclass = object()
_promote = object()
NamedTuple = object()
no_type_check = object()
NewType = object()

Expand Down Expand Up @@ -418,3 +417,9 @@ class Pattern(Generic[AnyStr]):
# Functions

def get_type_hints(obj: Callable) -> dict[str, Any]: ...

# Type constructors

# NamedTuple is special-cased in the type checker; the initializer is ignored.
def NamedTuple(typename: str, fields: Iterable[Tuple[str, Any]], *,
verbose: bool = ..., rename: bool = ..., module: str = None) -> Type[tuple]: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fields can be more exact as Iterable[Tuple[str, Union[str, Type]]] or something like that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, a type annotation doesn't have to be a type (see python/typing#136). So better leave this as is, or use Union[str, Any].