-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
This comment has been minimized.
This comment has been minimized.
Thanks! From skimming the source code of the runtime version of this module, I think you may be correct that |
Thank you for the prompt feedback! Modified them to |
int | None
float | None
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
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: ... |
It is more consistent with the official document.
https://docs.python.org/3/library/ftplib.html