Skip to content
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

ftplib: Correct timeout option to float | None #11419

Merged
merged 2 commits into from
Feb 14, 2024

Conversation

heavywatal
Copy link
Contributor

It is more consistent with the official document.
https://docs.python.org/3/library/ftplib.html

This comment has been minimized.

@AlexWaygood
Copy link
Member

Thanks! From skimming the source code of the runtime version of this module, I think you may be correct that None is acceptable. However, I think we should use float | None instead of int | None. Type annotations were only added to the official docs a few weeks ago, and it looks like they didn't mean to imply that passing a float is incorrect. See the conversation at python/cpython#114359 (comment)

@heavywatal
Copy link
Contributor Author

Thank you for the prompt feedback! Modified them to float | None accordingly.

@Akuli Akuli changed the title ftplib: Correct timeout option to int | None ftplib: Correct timeout option to float | None Feb 14, 2024
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -31,7 +31,7 @@ class FTP:
sock: socket | None
welcome: str | None
passiveserver: int
timeout: int
timeout: float | None
Copy link
Member

Choose a reason for hiding this comment

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

Agree that this could be None -- the implementation specifically checks to see whether or not it's None: https://github.com/python/cpython/blob/46245b0d831b9f5b15b4a0483c785ea71bffef12/Lib/ftplib.py#L153-L154

Copy link
Member

Choose a reason for hiding this comment

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

The timeout value is also eventually passed to socket.create_connection here: https://github.com/python/cpython/blob/46245b0d831b9f5b15b4a0483c785ea71bffef12/Lib/ftplib.py#L158-L159

And our annotations for create_connection state that None is accepted:

typeshed/stdlib/socket.pyi

Lines 803 to 815 in 4124569

if sys.version_info >= (3, 11):
def create_connection(
address: tuple[str | None, int],
timeout: float | None = ..., # noqa: F811
source_address: _Address | None = None,
*,
all_errors: bool = False,
) -> socket: ...
else:
def create_connection(
address: tuple[str | None, int], timeout: float | None = ..., source_address: _Address | None = None # noqa: F811
) -> socket: ...

@AlexWaygood AlexWaygood merged commit a3d356c into python:main Feb 14, 2024
57 checks passed
@heavywatal heavywatal deleted the ftp-timeout-int-none branch February 14, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants