Skip to content

smtplib: Improve bytes handling #9094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions stdlib/smtplib.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from _typeshed import Self
from _typeshed import ReadableBuffer, Self, _BufferWithLen
from collections.abc import Sequence
from email.message import Message as _Message
from re import Pattern
Expand All @@ -9,6 +9,8 @@ from types import TracebackType
from typing import Any, Protocol, overload
from typing_extensions import TypeAlias

from _socket import _Address as _SourceAddress

__all__ = [
"SMTPException",
"SMTPServerDisconnected",
Expand All @@ -28,8 +30,6 @@ __all__ = [

_Reply: TypeAlias = tuple[int, bytes]
_SendErrs: TypeAlias = dict[str, _Reply]
# Should match source_address for socket.create_connection
_SourceAddress: TypeAlias = tuple[bytearray | bytes | str, int]

SMTP_PORT: int
SMTP_SSL_PORT: int
Expand Down Expand Up @@ -102,7 +102,7 @@ class SMTP:
) -> None: ...
def set_debuglevel(self, debuglevel: int) -> None: ...
def connect(self, host: str = ..., port: int = ..., source_address: _SourceAddress | None = ...) -> _Reply: ...
def send(self, s: bytes | str) -> None: ...
def send(self, s: ReadableBuffer | str) -> None: ...
def putcmd(self, cmd: str, args: str = ...) -> None: ...
def getreply(self) -> _Reply: ...
def docmd(self, cmd: str, args: str = ...) -> _Reply: ...
Expand All @@ -114,7 +114,7 @@ class SMTP:
def noop(self) -> _Reply: ...
def mail(self, sender: str, options: Sequence[str] = ...) -> _Reply: ...
def rcpt(self, recip: str, options: Sequence[str] = ...) -> _Reply: ...
def data(self, msg: bytes | str) -> _Reply: ...
def data(self, msg: ReadableBuffer | str) -> _Reply: ...
def verify(self, address: str) -> _Reply: ...
vrfy = verify
def expn(self, address: str) -> _Reply: ...
Expand All @@ -125,16 +125,16 @@ class SMTP:
@overload
def auth_cram_md5(self, challenge: None = ...) -> None: ...
@overload
def auth_cram_md5(self, challenge: bytes) -> str: ...
def auth_plain(self, challenge: bytes | None = ...) -> str: ...
def auth_login(self, challenge: bytes | None = ...) -> str: ...
def auth_cram_md5(self, challenge: ReadableBuffer) -> str: ...
def auth_plain(self, challenge: ReadableBuffer | None = ...) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The challenge parameter doesn't look like it's actually used for this one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next one doesn't really use it either, I figured I should be consistent with auth_cram_md5.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense, I figured as much!

def auth_login(self, challenge: ReadableBuffer | None = ...) -> str: ...
def login(self, user: str, password: str, *, initial_response_ok: bool = ...) -> _Reply: ...
def starttls(self, keyfile: str | None = ..., certfile: str | None = ..., context: SSLContext | None = ...) -> _Reply: ...
def sendmail(
self,
from_addr: str,
to_addrs: str | Sequence[str],
msg: bytes | str,
msg: _BufferWithLen | str,
mail_options: Sequence[str] = ...,
rcpt_options: Sequence[str] = ...,
) -> _SendErrs: ...
Expand Down