Skip to content

asynchat + asyncore: Python 3 compatibility#1402

Merged
gvanrossum merged 1 commit intopython:masterfrom
rkr-at-dbx:asynchat_asyncore
Jun 20, 2017
Merged

asynchat + asyncore: Python 3 compatibility#1402
gvanrossum merged 1 commit intopython:masterfrom
rkr-at-dbx:asynchat_asyncore

Conversation

@rkr-at-dbx
Copy link
Copy Markdown
Contributor

Convert various str to bytes; add missing dispatcher.close() method.

Copy link
Copy Markdown
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

The changes look good, but I left a few suggestions for further improvement.

Comment thread stdlib/2and3/asynchat.pyi
def found_terminator(self) -> None: ...
def set_terminator(self, term: Union[str, int, None]) -> None: ...
def get_terminator(self) -> Union[str, int, None]: ...
def set_terminator(self, term: Union[bytes, int, None]) -> None: ...
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From the code it looks like this also supports str in (at least) 3.6, if self.use_encoding is true. I'm not sure when use_encoding would be True though, and it's undocumented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That flag would have to be set by the client of this code. I'm pretty sure that no one ever has set it, nor ever will – it's broken in at least three different ways, possibly four.

Comment thread stdlib/2and3/asyncore.pyi Outdated
@@ -87,22 +89,22 @@ class dispatcher:

# return type is an address
def recvfrom(self, bufsize: int, flags: int = ...) -> Any: ...
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method and recvfrom_into don't actually exist directly but are inherited from the underlying socket object through a __getattr__ (I was confused for a while).

Comment thread stdlib/2and3/asyncore.pyi Outdated
def sendto(self, data: str, address: Union[tuple, str], flags: int = ...) -> int: ...
def recvfrom_into(self, buffer: bytes, nbytes: int, flags: int = ...) -> Any: ...
def recv_into(self, buffer: bytes, nbytes: int, flags: int = ...) -> Any: ...
def send(self, data: bytes, flags: int = ...) -> Optional[int]: ...
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In 3.6, the flags argument doesn't seem to exist and I don't think the return type is Optional.

Includes an update to smtpd, which uses asynchat.
Comment thread stdlib/2and3/asyncore.pyi
def accept(self) -> Optional[Tuple[socket.socket, Any]]: ...
def recv(self, buffer_size: int) -> str: ...
def log(self, message: Any) -> None: ...
def send(self, data: bytes) -> int: ...
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To reply to the now-concealed comment (sorry about that!): it looks like this was always the correct signature for dispatcher's sendflags never existed here, only in socket, and as far as I can tell the return type was never Optional.

@gvanrossum gvanrossum merged commit 4412744 into python:master Jun 20, 2017
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.

3 participants