Convert namedtuples to class syntax (#3321)

This commit is contained in:
Sebastian Rittau
2019-10-20 10:37:33 +02:00
committed by GitHub
parent 2b9dc7b9c2
commit ec7960a8cb
41 changed files with 397 additions and 383 deletions

View File

@@ -454,5 +454,8 @@ class _CursesWindow:
def vline(self, y: int, x: int, ch: _chtype, n: int) -> None: ...
if sys.version_info >= (3, 8):
_ncurses_version = NamedTuple("ncurses_version", [("major", int), ("minor", int), ("patch", int)])
class _ncurses_version(NamedTuple):
major: int
minor: int
patch: int
ncurses_version: _ncurses_version

View File

@@ -1,4 +1,3 @@
from typing import Union, IO, Optional, Type, NamedTuple, List, Tuple, Any, Text, overload
from typing_extensions import Literal
from types import TracebackType
@@ -6,8 +5,13 @@ import sys
class Error(Exception): ...
_aifc_params = NamedTuple('_aifc_params', [('nchannels', int), ('sampwidth', int), ('framerate', int),
('nframes', int), ('comptype', bytes), ('compname', bytes)])
class _aifc_params(NamedTuple):
nchannels: int
sampwidth: int
framerate: int
nframes: int
comptype: bytes
compname: bytes
_File = Union[Text, IO[bytes]]
_Marker = Tuple[int, int, bytes]

View File

@@ -1,6 +1,5 @@
import sys
from typing import List, NamedTuple, Optional, Union
from typing import List, Optional, Union
if sys.version_info >= (3, 3):
class _Method: ...

View File

@@ -13,10 +13,10 @@ else:
_ComparableNum = Union[Decimal, float]
_DecimalT = TypeVar('_DecimalT', bound=Decimal)
DecimalTuple = NamedTuple('DecimalTuple',
[('sign', int),
('digits', Tuple[int, ...]),
('exponent', int)])
class DecimalTuple(NamedTuple):
sign: int
digits: Tuple[int, ...]
exponent: int
ROUND_DOWN: str
ROUND_HALF_UP: str

View File

@@ -16,11 +16,10 @@ else:
_JunkCallback = Union[Callable[[Text], bool], Callable[[str], bool]]
Match = NamedTuple('Match', [
('a', int),
('b', int),
('size', int),
])
class Match(NamedTuple):
a: int
b: int
size: int
class SequenceMatcher(Generic[_T]):
def __init__(self, isjunk: Optional[Callable[[_T], bool]] = ...,

View File

@@ -21,19 +21,15 @@ _have_code_or_string = Union[_have_code, str, bytes]
if sys.version_info >= (3, 4):
Instruction = NamedTuple(
"Instruction",
[
('opname', str),
('opcode', int),
('arg', Optional[int]),
('argval', Any),
('argrepr', str),
('offset', int),
('starts_line', Optional[int]),
('is_jump_target', bool)
]
)
class Instruction(NamedTuple):
opname: str
opcode: int
arg: Optional[int]
argval: Any
argrepr: str
offset: int
starts_line: Optional[int]
is_jump_target: bool
class Bytecode:
codeobj: types.CodeType

View File

@@ -4,10 +4,9 @@ import sys
import types
import unittest
TestResults = NamedTuple('TestResults', [
('failed', int),
('attempted', int),
])
class TestResults(NamedTuple):
failed: int
attempted: int
OPTIONFLAGS_BY_NAME: Dict[str, int]
def register_optionflag(name: str) -> int: ...

View File

@@ -1,9 +1,10 @@
from typing import List, NamedTuple, Optional
struct_group = NamedTuple("struct_group", [("gr_name", str),
("gr_passwd", Optional[str]),
("gr_gid", int),
("gr_mem", List[str])])
class struct_group(NamedTuple):
gr_name: str
gr_passwd: Optional[str]
gr_gid: int
gr_mem: List[str]
def getgrall() -> List[struct_group]: ...
def getgrgid(gid: int) -> struct_group: ...

View File

@@ -9,7 +9,10 @@ else:
Loader = Any
if sys.version_info >= (3, 6):
ModuleInfo = NamedTuple('ModuleInfo', [('module_finder', Any), ('name', str), ('ispkg', bool)])
class ModuleInfo(NamedTuple):
module_finder: Any
name: str
ispkg: bool
_YMFNI = Generator[ModuleInfo, None, None]
else:
_YMFNI = Generator[Tuple[Any, str, bool], None, None]

View File

@@ -1,13 +1,12 @@
import sys
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Text, Tuple
Event = NamedTuple('Event', [
('time', float),
('priority', Any),
('action', Callable[..., Any]),
('argument', Tuple[Any, ...]),
('kwargs', Dict[Text, Any]),
])
class Event(NamedTuple):
time: float
priority: Any
action: Callable[..., Any]
argument: Tuple[Any, ...]
kwargs: Dict[Text, Any]
class scheduler:
if sys.version_info >= (3, 3):

View File

@@ -114,9 +114,10 @@ else:
def move(src: _Path, dst: _Path) -> _PathReturn: ...
if sys.version_info >= (3,):
_ntuple_diskusage = NamedTuple('usage', [('total', int),
('used', int),
('free', int)])
class _ntuple_diskusage(NamedTuple):
total: int
used: int
free: int
def disk_usage(path: _Path) -> _ntuple_diskusage: ...
def chown(path: _Path, user: Optional[str] = ...,
group: Optional[str] = ...) -> None: ...

View File

@@ -5,13 +5,12 @@ import sys
from typing import Any, NamedTuple, Optional, Tuple, Union
if sys.version_info >= (3, 5):
SndHeaders = NamedTuple('SndHeaders', [
('filetype', str),
('framerate', int),
('nchannels', int),
('nframes', int),
('sampwidth', Union[int, str]),
])
class SndHeaders(NamedTuple):
filetype: str
framerate: int
nchannels: int
nframes: int
sampwidth: Union[int, str]
_SndHeaders = SndHeaders
else:
_SndHeaders = Tuple[str, int, int, int, Union[int, str]]

View File

@@ -87,12 +87,13 @@ def get_server_certificate(addr: Tuple[str, int], ssl_version: int = ...,
ca_certs: Optional[str] = ...) -> str: ...
def DER_cert_to_PEM_cert(der_cert_bytes: bytes) -> str: ...
def PEM_cert_to_DER_cert(pem_cert_string: str) -> bytes: ...
DefaultVerifyPaths = NamedTuple('DefaultVerifyPaths',
[('cafile', str), ('capath', str),
('openssl_cafile_env', str),
('openssl_cafile', str),
('openssl_capath_env', str),
('openssl_capath', str)])
class DefaultVerifyPaths(NamedTuple):
cafile: str
capath: str
openssl_cafile_env: str
openssl_cafile: str
openssl_capath_env: str
openssl_capath: str
def get_default_verify_paths() -> DefaultVerifyPaths: ...
if sys.platform == 'win32':
@@ -173,13 +174,16 @@ ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: int
ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: int
ALERT_DESCRIPTION_USER_CANCELLED: int
class _ASN1Object(NamedTuple):
nid: int
shortname: str
longname: str
oid: str
if sys.version_info < (3,):
class _ASN1Object(NamedTuple('_ASN1Object', [('nid', int), ('shortname', str), ('longname', str), ('oid', str)])): ...
class Purpose(_ASN1Object):
SERVER_AUTH: ClassVar[Purpose]
CLIENT_AUTH: ClassVar[Purpose]
else:
class _ASN1Object(NamedTuple('_ASN1Object', [('nid', int), ('shortname', str), ('longname', str), ('oid', str)])): ...
class Purpose(_ASN1Object, enum.Enum):
SERVER_AUTH: _ASN1Object
CLIENT_AUTH: _ASN1Object

View File

@@ -25,14 +25,13 @@ AUDIO_UNKNOWN_SIZE: int
if sys.version_info < (3, 0):
_sunau_params = Tuple[int, int, int, int, str, str]
else:
_sunau_params = NamedTuple('_sunau_params', [
('nchannels', int),
('sampwidth', int),
('framerate', int),
('nframes', int),
('comptype', str),
('compname', str),
])
class _sunau_params(NamedTuple):
nchannels: int
sampwidth: int
framerate: int
nframes: int
comptype: str
compname: str
class Au_read:
def __init__(self, f: _File) -> None: ...

View File

@@ -32,15 +32,19 @@ if sys.version_info >= (3, 8) and sys.platform == "darwin":
CLOCK_UPTIME_RAW: int
if sys.version_info >= (3, 3):
class struct_time(
NamedTuple(
'_struct_time',
[('tm_year', int), ('tm_mon', int), ('tm_mday', int),
('tm_hour', int), ('tm_min', int), ('tm_sec', int),
('tm_wday', int), ('tm_yday', int), ('tm_isdst', int),
('tm_zone', str), ('tm_gmtoff', int)]
)
):
class _struct_time(NamedTuple):
tm_year: int
tm_mon: int
tm_mday: int
tm_hour: int
tm_min: int
tm_sec: int
tm_wday: int
tm_yday: int
tm_isdst: int
tm_zone: str
tm_gmtoff: int
class struct_time(_struct_time):
def __init__(
self,
o: Union[
@@ -60,14 +64,17 @@ if sys.version_info >= (3, 3):
_arg: Any = ...,
) -> struct_time: ...
else:
class struct_time(
NamedTuple(
'_struct_time',
[('tm_year', int), ('tm_mon', int), ('tm_mday', int),
('tm_hour', int), ('tm_min', int), ('tm_sec', int),
('tm_wday', int), ('tm_yday', int), ('tm_isdst', int)]
)
):
class _struct_time(NamedTuple):
tm_year: int
tm_mon: int
tm_mday: int
tm_hour: int
tm_min: int
tm_sec: int
tm_wday: int
tm_yday: int
tm_isdst: int
class struct_time(_struct_time):
def __init__(self, o: _TimeTuple, _arg: Any = ...) -> None: ...
def __new__(cls, o: _TimeTuple, _arg: Any = ...) -> struct_time: ...

View File

@@ -29,13 +29,13 @@ def simplefilter(action: str, category: Type[Warning] = ..., lineno: int = ...,
append: bool = ...) -> None: ...
def resetwarnings() -> None: ...
_Record = NamedTuple('_Record',
[('message', str),
('category', Type[Warning]),
('filename', str),
('lineno', int),
('file', Optional[TextIO]),
('line', Optional[str])])
class _Record(NamedTuple):
message: str
category: Type[Warning]
filename: str
lineno: int
file: Optional[TextIO]
line: Optional[str]
class catch_warnings:
def __init__(self, *, record: bool = ...,

View File

@@ -14,14 +14,13 @@ WAVE_FORMAT_PCM: int
if sys.version_info < (3, 0):
_wave_params = Tuple[int, int, int, int, str, str]
else:
_wave_params = NamedTuple('_wave_params', [
('nchannels', int),
('sampwidth', int),
('framerate', int),
('nframes', int),
('comptype', str),
('compname', str),
])
class _wave_params(NamedTuple):
nchannels: int
sampwidth: int
framerate: int
nframes: int
comptype: str
compname: str
class Wave_read:
def __init__(self, f: _File) -> None: ...