From d74f712f5b811bd9ee733aba870305aef65abdc4 Mon Sep 17 00:00:00 2001 From: savanto Date: Sat, 27 Dec 2025 14:31:40 -0600 Subject: [PATCH 1/2] imaplib: append accepts None args Docstring for append method says: ``` All args except `message' can be None. ``` [v3.0](https://github.com/python/cpython/blob/v3.0/Lib/imaplib.py#L318) [v3.14](https://github.com/python/cpython/blob/v3.14.0/Lib/imaplib.py#L485) The body of the method performs truthiness checks on each argument except `message` and sets them to an appropriate value or None anyway. --- stdlib/imaplib.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/imaplib.pyi b/stdlib/imaplib.pyi index 1f0e0106006b..57d78a805ac4 100644 --- a/stdlib/imaplib.pyi +++ b/stdlib/imaplib.pyi @@ -61,7 +61,9 @@ class IMAP4: def socket(self) -> _socket: ... def recent(self) -> _CommandResults: ... def response(self, code: str) -> _CommandResults: ... - def append(self, mailbox: str, flags: str, date_time: str, message: ReadableBuffer) -> tuple[str, _list[bytes]]: ... + def append( + self, mailbox: str | None, flags: str | None, date_time: str | None, message: ReadableBuffer + ) -> tuple[str, _list[bytes]]: ... def authenticate(self, mechanism: str, authobject: Callable[[bytes], bytes | None]) -> tuple[str, str]: ... def capability(self) -> _CommandResults: ... def check(self) -> _CommandResults: ... From bdb2cf9da60aa08bec9526dca6aeffb52e13def2 Mon Sep 17 00:00:00 2001 From: savanto Date: Sat, 27 Dec 2025 14:36:03 -0600 Subject: [PATCH 2/2] imaplib: append arg date_time is a union The append method passes `date_time` (after None check) immediately into the `Time2Internaldate` function, so it seems reasonable to have append accept anything that `Time2Internaldate` would accept. --- stdlib/imaplib.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/imaplib.pyi b/stdlib/imaplib.pyi index 57d78a805ac4..4748ddd8e294 100644 --- a/stdlib/imaplib.pyi +++ b/stdlib/imaplib.pyi @@ -62,7 +62,7 @@ class IMAP4: def recent(self) -> _CommandResults: ... def response(self, code: str) -> _CommandResults: ... def append( - self, mailbox: str | None, flags: str | None, date_time: str | None, message: ReadableBuffer + self, mailbox: str | None, flags: str | None, date_time: _TimeLike | None, message: ReadableBuffer ) -> tuple[str, _list[bytes]]: ... def authenticate(self, mechanism: str, authobject: Callable[[bytes], bytes | None]) -> tuple[str, str]: ... def capability(self) -> _CommandResults: ... @@ -174,4 +174,7 @@ class _Authenticator: def Internaldate2tuple(resp: ReadableBuffer) -> time.struct_time | None: ... def Int2AP(num: SupportsAbs[SupportsInt]) -> bytes: ... def ParseFlags(resp: ReadableBuffer) -> tuple[bytes, ...]: ... -def Time2Internaldate(date_time: float | time.struct_time | time._TimeTuple | datetime | str) -> str: ... + +_TimeLike: TypeAlias = float | time.struct_time | time._TimeTuple | datetime | str + +def Time2Internaldate(date_time: _TimeLike) -> str: ...