mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 21:46:42 +08:00
Convert namedtuples to class syntax (#3321)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]] = ...,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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]]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
|
||||
@@ -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 = ...,
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user