mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
Convert namedtuples to class syntax (#3321)
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from typing import Any, Callable, Generic, Dict, Iterable, Optional, Sequence, Tuple, TypeVar, overload
|
||||
from collections import namedtuple
|
||||
|
||||
_AnyCallable = Callable[..., Any]
|
||||
|
||||
|
||||
@@ -22,11 +22,12 @@ CO_VARARGS: int
|
||||
CO_VARKEYWORDS: int
|
||||
TPFLAGS_IS_ABSTRACT: int
|
||||
|
||||
ModuleInfo = NamedTuple('ModuleInfo', [('name', str),
|
||||
('suffix', str),
|
||||
('mode', str),
|
||||
('module_type', int),
|
||||
])
|
||||
class ModuleInfo(NamedTuple):
|
||||
name: str
|
||||
suffix: str
|
||||
mode: str
|
||||
module_type: int
|
||||
|
||||
def getmembers(
|
||||
object: object,
|
||||
predicate: Optional[Callable[[Any], bool]] = ...
|
||||
@@ -70,22 +71,22 @@ def indentsize(line: str) -> int: ...
|
||||
# Classes and functions
|
||||
def getclasstree(classes: List[type], unique: bool = ...) -> List[Union[Tuple[type, Tuple[type, ...]], List[Any]]]: ...
|
||||
|
||||
ArgSpec = NamedTuple('ArgSpec', [('args', List[str]),
|
||||
('varargs', Optional[str]),
|
||||
('keywords', Optional[str]),
|
||||
('defaults', Tuple[Any, ...]),
|
||||
])
|
||||
class ArgSpec(NamedTuple):
|
||||
args: List[str]
|
||||
varargs: Optional[str]
|
||||
keywords: Optional[str]
|
||||
defaults: Tuple[Any, ...]
|
||||
|
||||
ArgInfo = NamedTuple('ArgInfo', [('args', List[str]),
|
||||
('varargs', Optional[str]),
|
||||
('keywords', Optional[str]),
|
||||
('locals', Dict[str, Any]),
|
||||
])
|
||||
class ArgInfo(NamedTuple):
|
||||
args: List[str]
|
||||
varargs: Optional[str]
|
||||
keywords: Optional[str]
|
||||
locals: Dict[str, Any]
|
||||
|
||||
Arguments = NamedTuple('Arguments', [('args', List[Union[str, List[Any]]]),
|
||||
('varargs', Optional[str]),
|
||||
('keywords', Optional[str]),
|
||||
])
|
||||
class Arguments(NamedTuple):
|
||||
args: List[Union[str, List[Any]]]
|
||||
varargs: Optional[str]
|
||||
keywords: Optional[str]
|
||||
|
||||
def getargs(co: CodeType) -> Arguments: ...
|
||||
def getargspec(func: object) -> ArgSpec: ...
|
||||
@@ -101,16 +102,12 @@ def getcallargs(func, *args, **kwds) -> Dict[str, Any]: ...
|
||||
|
||||
# The interpreter stack
|
||||
|
||||
Traceback = NamedTuple(
|
||||
'Traceback',
|
||||
[
|
||||
('filename', str),
|
||||
('lineno', int),
|
||||
('function', str),
|
||||
('code_context', Optional[List[str]]),
|
||||
('index', Optional[int]),
|
||||
]
|
||||
)
|
||||
class Traceback(NamedTuple):
|
||||
filename: str
|
||||
lineno: int
|
||||
function: str
|
||||
code_context: Optional[List[str]]
|
||||
index: Optional[int] # type: ignore
|
||||
|
||||
_FrameInfo = Tuple[FrameType, str, int, str, Optional[List[str]], Optional[int]]
|
||||
|
||||
@@ -123,10 +120,10 @@ def currentframe(depth: int = ...) -> FrameType: ...
|
||||
def stack(context: int = ...) -> List[_FrameInfo]: ...
|
||||
def trace(context: int = ...) -> List[_FrameInfo]: ...
|
||||
|
||||
Attribute = NamedTuple('Attribute', [('name', str),
|
||||
('kind', str),
|
||||
('defining_class', type),
|
||||
('object', object),
|
||||
])
|
||||
class Attribute(NamedTuple):
|
||||
name: str
|
||||
kind: str
|
||||
defining_class: type
|
||||
object: object
|
||||
|
||||
def classify_class_attrs(cls: type) -> List[Attribute]: ...
|
||||
|
||||
@@ -136,10 +136,17 @@ if sys.version_info >= (3, 6):
|
||||
|
||||
_PathType = path._PathType
|
||||
|
||||
_StatVFS = NamedTuple('_StatVFS', [('f_bsize', int), ('f_frsize', int), ('f_blocks', int),
|
||||
('f_bfree', int), ('f_bavail', int), ('f_files', int),
|
||||
('f_ffree', int), ('f_favail', int), ('f_flag', int),
|
||||
('f_namemax', int)])
|
||||
class _StatVFS(NamedTuple):
|
||||
f_bsize: int
|
||||
f_frsize: int
|
||||
f_blocks: int
|
||||
f_bfree: int
|
||||
f_bavail: int
|
||||
f_files: int
|
||||
f_ffree: int
|
||||
f_favail: int
|
||||
f_flag: int
|
||||
f_namemax: int
|
||||
|
||||
def getlogin() -> str: ...
|
||||
def getpid() -> int: ...
|
||||
@@ -349,20 +356,3 @@ if sys.version_info < (3, 0):
|
||||
P_ALL: int
|
||||
WEXITED: int
|
||||
WNOWAIT: int
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
if sys.platform != 'win32':
|
||||
# Unix only
|
||||
def sync() -> None: ...
|
||||
|
||||
def truncate(path: Union[_PathType, int], length: int) -> None: ... # Unix only up to version 3.4
|
||||
|
||||
def fwalk(top: AnyStr = ..., topdown: bool = ...,
|
||||
onerror: Callable = ..., *, follow_symlinks: bool = ...,
|
||||
dir_fd: int = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], List[AnyStr], int]]: ...
|
||||
|
||||
terminal_size = NamedTuple('terminal_size', [('columns', int), ('lines', int)])
|
||||
def get_terminal_size(fd: int = ...) -> terminal_size: ...
|
||||
|
||||
if sys.version_info >= (3, 4):
|
||||
def cpu_count() -> Optional[int]: ...
|
||||
|
||||
@@ -19,12 +19,24 @@ RLIMIT_MEMLOCK: int
|
||||
RLIMIT_VMEM: int
|
||||
RLIMIT_AS: int
|
||||
|
||||
_RUsage = NamedTuple('_RUsage', [('ru_utime', float), ('ru_stime', float), ('ru_maxrss', int),
|
||||
('ru_ixrss', int), ('ru_idrss', int), ('ru_isrss', int),
|
||||
('ru_minflt', int), ('ru_majflt', int), ('ru_nswap', int),
|
||||
('ru_inblock', int), ('ru_oublock', int), ('ru_msgsnd', int),
|
||||
('ru_msgrcv', int), ('ru_nsignals', int), ('ru_nvcsw', int),
|
||||
('ru_nivcsw', int)])
|
||||
class _RUsage(NamedTuple):
|
||||
ru_utime: float
|
||||
ru_stime: float
|
||||
ru_maxrss: int
|
||||
ru_ixrss: int
|
||||
ru_idrss: int
|
||||
ru_isrss: int
|
||||
ru_minflt: int
|
||||
ru_majflt: int
|
||||
ru_nswap: int
|
||||
ru_inblock: int
|
||||
ru_oublock: int
|
||||
ru_msgsnd: int
|
||||
ru_msgrcv: int
|
||||
ru_nsignals: int
|
||||
ru_nvcsw: int
|
||||
ru_nivcsw: int
|
||||
|
||||
def getrusage(who: int) -> _RUsage: ...
|
||||
def getpagesize() -> int: ...
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
from typing import List, NamedTuple
|
||||
|
||||
struct_spwd = NamedTuple("struct_spwd", [("sp_nam", str),
|
||||
("sp_pwd", str),
|
||||
("sp_lstchg", int),
|
||||
("sp_min", int),
|
||||
("sp_max", int),
|
||||
("sp_warn", int),
|
||||
("sp_inact", int),
|
||||
("sp_expire", int),
|
||||
("sp_flag", int)])
|
||||
class struct_spwd(NamedTuple):
|
||||
sp_nam: str
|
||||
sp_pwd: str
|
||||
sp_lstchg: int
|
||||
sp_min: int
|
||||
sp_max: int
|
||||
sp_warn: int
|
||||
sp_inact: int
|
||||
sp_expire: int
|
||||
sp_flag: int
|
||||
|
||||
def getspall() -> List[struct_spwd]: ...
|
||||
def getspnam(name: str) -> struct_spwd: ...
|
||||
|
||||
@@ -25,27 +25,23 @@ class ResultMixin(object):
|
||||
@property
|
||||
def port(self) -> Optional[int]: ...
|
||||
|
||||
class SplitResult(
|
||||
NamedTuple(
|
||||
'SplitResult',
|
||||
[
|
||||
('scheme', str), ('netloc', str), ('path', str), ('query', str), ('fragment', str)
|
||||
]
|
||||
),
|
||||
ResultMixin
|
||||
):
|
||||
class _SplitResult(NamedTuple):
|
||||
scheme: str
|
||||
netloc: str
|
||||
path: str
|
||||
query: str
|
||||
fragment: str
|
||||
class SplitResult(_SplitResult, ResultMixin):
|
||||
def geturl(self) -> str: ...
|
||||
|
||||
class ParseResult(
|
||||
NamedTuple(
|
||||
'ParseResult',
|
||||
[
|
||||
('scheme', str), ('netloc', str), ('path', str), ('params', str), ('query', str),
|
||||
('fragment', str)
|
||||
]
|
||||
),
|
||||
ResultMixin
|
||||
):
|
||||
class _ParseResult(NamedTuple):
|
||||
scheme: str
|
||||
netloc: str
|
||||
path: str
|
||||
params: str
|
||||
query: str
|
||||
fragment: str
|
||||
class ParseResult(_ParseResult, ResultMixin):
|
||||
def geturl(self) -> str: ...
|
||||
|
||||
def urlparse(url: _String, scheme: _String = ...,
|
||||
|
||||
Reference in New Issue
Block a user