8000 ftplib: Correct timeout option to `float | None` by heavywatal · Pull Request #11419 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

ftplib: Correct timeout option to float | None #11419

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 2 commits into from
Feb 14, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
ftplib: Accept float | None according to python/cpython#114359
  • Loading branch information
heavywatal committed Feb 14, 2024
commit cdb459653b2df879b1ee74f36b557f414648b985
14 changes: 7 additions & 7 deletions stdlib/ftplib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FTP:
sock: socket | None
welcome: str | None
passiveserver: int
timeout: int | None
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: ...

af: int
lastresp: str
file: TextIO | None
Expand All @@ -48,7 +48,7 @@ class FTP:
user: str = "",
passwd: str = "",
acct: str = "",
timeout: int | None = ...,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
*,
encoding: str = "utf-8",
Expand All @@ -60,12 +60,12 @@ class FTP:
user: str = "",
passwd: str = "",
acct: str = "",
timeout: int | None = ...,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
) -> None: ...

def connect(
self, host: str = "", port: int = 0, timeout: int = -999, source_address: tuple[str, int] | None = None
self, host: str = "", port: int = 0, timeout: float = -999, source_address: tuple[str, int] | None = None
) -> str: ...
def getwelcome(self) -> str: ...
def set_debuglevel(self, level: int) -> None: ...
Expand Down Expand Up @@ -127,7 +127,7 @@ class FTP_TLS(FTP):
acct: str = "",
*,
context: SSLContext | None = None,
timeout: int | None = ...,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
encoding: str = "utf-8",
) -> None: ...
Expand All @@ -141,7 +141,7 @@ class FTP_TLS(FTP):
keyfile: str | None = None,
certfile: str | None = None,
context: SSLContext | None = None,
timeout: int | None = ...,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
*,
encoding: str = "utf-8",
Expand All @@ -156,7 +156,7 @@ class FTP_TLS(FTP):
keyfile: str | None = None,
certfile: str | None = None,
context: SSLContext | None = None,
timeout: int | None = ...,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
) -> None: ...
ssl_version: int
Expand Down
0