Skip to content

gh-137339: Clarify host and port parameter behavior in smtplib.SMTP_SSL initialization #137340

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Aniketsy
Copy link

@Aniketsy Aniketsy commented Aug 3, 2025

(GH #137339)
This PR updates the documentation for the smtplib.SMTP_SSL class to explicitly clarify the behavior of the host and port parameters during initialization.
Specifically, it now states that if host is omitted or an empty string, no connection is made during initialization and connect() must be called manually. It also clarifies that if port is zero,

Please let me know if this fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.
Thankyou!


📚 Documentation preview 📚: https://cpython-previews--137340.org.readthedocs.build/

@Aniketsy Aniketsy requested a review from a team as a code owner August 3, 2025 11:48
@python-cla-bot
Copy link

python-cla-bot bot commented Aug 3, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app bedevere-app bot added awaiting review docs Documentation in the Doc dir skip news labels Aug 3, 2025
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Aug 3, 2025
@picnixz picnixz changed the title Clarify host and port parameter behavior in smtplib.SMTP_SSL initialization (GH #137339) gh-137339: Clarify host and port parameter behavior in smtplib.SMTP_SSL initialization Aug 3, 2025
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

I don't think this requires a change as we already mention what happens when the optional parameters are given. If you want to rephrase it, you should remove the "if the optional parameters are given then [...¨]" as it makes the paragraph more confusing IMO.

called with those parameters during initialization.If *host* is omitted or
an empty string, no connection is made during initialization; you must
call :meth:`connect` manually before using the instance.
If *port* is zero, the default SMTP port (25) is used. If specified,
Copy link
Member

Choose a reason for hiding this comment

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

This is not always the case that the default SMTP port is 25. It depends on the default_port attribute. Also, this now contradicts the last sentence:

If omitted (or if host or port are '' and/or 0
respectively) the OS default behavior will be used.

We should also make more paragraphs. This description is too compact for the reader.

Copy link
Author

Choose a reason for hiding this comment

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

If port is zero, the value of the instance's default_port attribute will be used.

I'd appreciate any insights or suggestions to expand our descriptions so that its not too compact for reader

@@ -26,7 +26,10 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
An :class:`SMTP` instance encapsulates an SMTP connection. It has methods
that support a full repertoire of SMTP and ESMTP operations. If the optional
*host* and *port* parameters are given, the SMTP :meth:`connect` method is
called with those parameters during initialization. If specified,
called with those parameters during initialization.If *host* is omitted or
Copy link
Member

@picnixz picnixz Aug 3, 2025

Choose a reason for hiding this comment

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

This is already hinted in the previous sentence and this would somehow conflict with the last sentence IMO.

If the optional host and port parameters are given, the SMTP :meth:connect method is called with those parameters during initialization

@Aniketsy
Copy link
Author

Aniketsy commented Aug 3, 2025

Thankyou for the feedback !
I will remove this "if the optional parameters are given then [...¨]" as it makes the paragraph more confusing.

Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

My comment from the issue:

As for this one,

If the optional host and port parameters are given, connect() is called with those parameters during initialization. If host is omitted or empty, no connection is made; connect() must be called manually. If port is zero, the default SMTP port (25) is used.

I think we can simplify by stating that host is not optional. connect is linked and there you can find further details on behaviour, duplicate docs will simply create problems down the line.

The host and optional port arguments are passed to connect during initialization.

@picnixz
Copy link
Member

picnixz commented Aug 3, 2025

I think we can simplify by stating that host is not optional

It is optional though?

The host and optional port arguments are passed to connect during initialization.

This is incorrect. connect() is only called in __init__ if the host is truthy. It's never called otherwise.

@Aniketsy
Copy link
Author

Aniketsy commented Aug 3, 2025

@picnixz
I have removed the contradiction part as per your suggestions. I would also love to work on this part (We should also make more paragraphs. This description is too compact for the reader) .
Thankyou !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants