Use NamedTuple for inspect.ArgSpec and .FullArgSpec.

This commit is contained in:
Guido van Rossum
2016-01-18 16:50:00 -08:00
parent f1beef02e7
commit 740568ed25
2 changed files with 20 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
# TODO incomplete
from typing import Any, List, Tuple
from typing import Any, List, Tuple, NamedTuple
def isgenerator(object: Any) -> bool: ...
@@ -10,11 +10,10 @@ _FrameRecord = Tuple[_Frame, str, int, str, List[str], int]
def currentframe() -> _FrameRecord: ...
def stack(context: int = ...) -> List[_FrameRecord]: ...
# namedtuple('ArgSpec', 'args varargs keywords defaults')
class ArgSpec(tuple):
args = ... # type: List[str]
varargs = ... # type: str
keywords = ... # type: str
defaults = ... # type: tuple
ArgSpec = NamedTuple('ArgSpec', [('args', List[str]),
('varargs', str),
('keywords', str),
('defaults', tuple),
])
def getargspec(func: object) -> ArgSpec: ...

View File

@@ -1,6 +1,6 @@
# Stubs for inspect
from typing import Any, Tuple, List, Dict, Callable
from typing import Any, Tuple, List, Dict, Callable, NamedTuple
from types import FrameType
_object = object
@@ -22,24 +22,22 @@ def cleandoc(doc: str) -> str: ...
def getsourcelines(obj: object) -> Tuple[List[str], int]: ...
# namedtuple('ArgSpec', 'args varargs keywords defaults')
class ArgSpec(tuple):
args = ... # type: List[str]
varargs = ... # type: str
keywords = ... # type: str
defaults = ... # type: tuple
ArgSpec = NamedTuple('ArgSpec', [('args', List[str]),
('varargs', str),
('keywords', str),
('defaults', tuple),
])
def getargspec(func: object) -> ArgSpec: ...
# namedtuple('FullArgSpec', 'args varargs varkw defaults kwonlyargs kwonlydefaults annotations')
class FullArgSpec(tuple):
args = ... # type: List[str]
varargs = ... # type: str
varkw = ... # type: str
defaults = ... # type: tuple
kwonlyargs = ... # type: List[str]
kwonlydefaults = ... # type: Dict[str, Any]
annotations = ... # type: Dict[str, Any]
FullArgSpec = NamedTuple('FullArgSpec', [('args', List[str]),
('varargs', str),
('varkw', str),
('defaults', tuple),
('kwonlyargs', List[str]),
('kwonlydefaults', Dict[str, Any]),
('annotations', Dict[str, Any]),
])
def getfullargspec(func: object) -> FullArgSpec: ...