From bf5ff49b53448259f07aa171eb11cd4f8fbc6e46 Mon Sep 17 00:00:00 2001 From: hatal175 Date: Thu, 22 Apr 2021 07:58:01 +0300 Subject: [PATCH] mailbox, mimetypes, unittest, zipfile: stubtest fixes (#5239) --- stdlib/mailbox.pyi | 18 +++++++----------- stdlib/mimetypes.pyi | 2 +- stdlib/unittest/__init__.pyi | 16 +++++++++++++++- stdlib/zipfile.pyi | 9 ++++++++- tests/stubtest_whitelists/py38.txt | 2 -- tests/stubtest_whitelists/py3_common.txt | 10 +--------- 6 files changed, 32 insertions(+), 25 deletions(-) diff --git a/stdlib/mailbox.pyi b/stdlib/mailbox.pyi index e22788d21..d968e7d77 100644 --- a/stdlib/mailbox.pyi +++ b/stdlib/mailbox.pyi @@ -100,20 +100,18 @@ class Maildir(Mailbox[MaildirMessage]): class _singlefileMailbox(Mailbox[_MessageT]): ... class _mboxMMDF(_singlefileMailbox[_MessageT]): - def get_file(self, key: str) -> _PartialFile[bytes]: ... + def get_file(self, key: str, from_: bool = ...) -> _PartialFile[bytes]: ... + def get_bytes(self, key: str, from_: bool = ...) -> bytes: ... + def get_string(self, key: str, from_: bool = ...) -> str: ... class mbox(_mboxMMDF[mboxMessage]): - def __init__( - self, dirname: AnyPath, factory: Optional[Callable[[IO[Any]], mboxMessage]] = ..., create: bool = ... - ) -> None: ... + def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], mboxMessage]] = ..., create: bool = ...) -> None: ... class MMDF(_mboxMMDF[MMDFMessage]): - def __init__( - self, dirname: AnyPath, factory: Optional[Callable[[IO[Any]], MMDFMessage]] = ..., create: bool = ... - ) -> None: ... + def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], MMDFMessage]] = ..., create: bool = ...) -> None: ... class MH(Mailbox[MHMessage]): - def __init__(self, dirname: AnyPath, factory: Optional[Callable[[IO[Any]], MHMessage]] = ..., create: bool = ...) -> None: ... + def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], MHMessage]] = ..., create: bool = ...) -> None: ... def get_file(self, key: str) -> _ProxyFile[bytes]: ... def list_folders(self) -> List[str]: ... def get_folder(self, folder: AnyPath) -> MH: ... @@ -124,9 +122,7 @@ class MH(Mailbox[MHMessage]): def pack(self) -> None: ... class Babyl(_singlefileMailbox[BabylMessage]): - def __init__( - self, dirname: AnyPath, factory: Optional[Callable[[IO[Any]], BabylMessage]] = ..., create: bool = ... - ) -> None: ... + def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], BabylMessage]] = ..., create: bool = ...) -> None: ... def get_file(self, key: str) -> IO[bytes]: ... def get_labels(self) -> List[str]: ... diff --git a/stdlib/mimetypes.pyi b/stdlib/mimetypes.pyi index 43f27dda4..f0cfac32c 100644 --- a/stdlib/mimetypes.pyi +++ b/stdlib/mimetypes.pyi @@ -11,7 +11,7 @@ else: def guess_all_extensions(type: str, strict: bool = ...) -> List[str]: ... def guess_extension(type: str, strict: bool = ...) -> Optional[str]: ... def init(files: Optional[Sequence[str]] = ...) -> None: ... -def read_mime_types(filename: str) -> Optional[Dict[str, str]]: ... +def read_mime_types(file: str) -> Optional[Dict[str, str]]: ... def add_type(type: str, ext: str, strict: bool = ...) -> None: ... inited: bool diff --git a/stdlib/unittest/__init__.pyi b/stdlib/unittest/__init__.pyi index aadaa610a..b94cc8d9c 100644 --- a/stdlib/unittest/__init__.pyi +++ b/stdlib/unittest/__init__.pyi @@ -1,6 +1,20 @@ +import sys from typing import Optional from unittest.async_case import * -from unittest.case import * + +from .case import ( + FunctionTestCase as FunctionTestCase, + SkipTest as SkipTest, + TestCase as TestCase, + expectedFailure as expectedFailure, + skip as skip, + skipIf as skipIf, + skipUnless as skipUnless, +) + +if sys.version_info >= (3, 8): + from .case import addModuleCleanup as addModuleCleanup + from unittest.loader import * from unittest.main import * from unittest.result import TestResult as TestResult diff --git a/stdlib/zipfile.pyi b/stdlib/zipfile.pyi index 941e79b96..91727aa54 100644 --- a/stdlib/zipfile.pyi +++ b/stdlib/zipfile.pyi @@ -186,6 +186,9 @@ class ZipInfo: def is_dir(self) -> bool: ... def FileHeader(self, zip64: Optional[bool] = ...) -> bytes: ... +class _PathOpenProtocol(Protocol): + def __call__(self, mode: str = ..., pwd: Optional[bytes] = ..., *, force_zip64: bool = ...) -> IO[bytes]: ... + if sys.version_info >= (3, 8): class Path: @property @@ -193,7 +196,11 @@ if sys.version_info >= (3, 8): @property def parent(self) -> Path: ... # undocumented def __init__(self, root: Union[ZipFile, StrPath, IO[bytes]], at: str = ...) -> None: ... - def open(self, mode: str = ..., pwd: Optional[bytes] = ..., *, force_zip64: bool = ...) -> IO[bytes]: ... + if sys.version_info >= (3, 9): + def open(self, mode: str = ..., pwd: Optional[bytes] = ..., *, force_zip64: bool = ...) -> IO[bytes]: ... + else: + @property + def open(self) -> _PathOpenProtocol: ... def iterdir(self) -> Iterator[Path]: ... def is_dir(self) -> bool: ... def is_file(self) -> bool: ... diff --git a/tests/stubtest_whitelists/py38.txt b/tests/stubtest_whitelists/py38.txt index e2cb0be85..6dea6ae2a 100644 --- a/tests/stubtest_whitelists/py38.txt +++ b/tests/stubtest_whitelists/py38.txt @@ -95,7 +95,6 @@ typing.SupportsInt.__init__ typing.SupportsRound.__init__ typing._SpecialForm.__init__ typing._SpecialForm.__new__ -unittest.doModuleCleanups uuid.getnode # undocumented, unused parameter getters that was later removed weakref.WeakValueDictionary.update webbrowser.Opera.raise_opts @@ -103,7 +102,6 @@ xml.etree.ElementTree.TreeBuilder.start # Discrepancy between Python and C modu xml.etree.ElementTree.XMLParser.__init__ # Defined in C so has general signature xml.etree.cElementTree.TreeBuilder.start # bpo-39495 xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signature -zipfile.Path.open # These enums derive from (int, IntEnum) or (str, Enum). See comment in py3_common.txt enum.IntFlag.__new__ pstats.SortKey.__new__ diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 32f52fafd..b4056470f 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -168,15 +168,7 @@ lib2to3.pytree.BasePattern.__new__ lib2to3.pytree.BasePattern.type lib2to3.pytree.NegatedPattern.match lib2to3.pytree.NegatedPattern.match_seq -mailbox.Babyl.__init__ -mailbox.MH.__init__ -mailbox.MMDF.__init__ -mailbox._mboxMMDF.get_bytes -mailbox._mboxMMDF.get_file -mailbox._mboxMMDF.get_string -mailbox.mbox.__init__ -mimetypes.read_mime_types -mmap.mmap.__iter__ +mmap.mmap.__iter__ # has __getitem__ but mypy doesn't derive __iter__ from it: https://github.com/python/mypy/issues/2220 multiprocessing.JoinableQueue multiprocessing.Queue multiprocessing.SimpleQueue