Skip to content

Fix DatagramRequestHandler.packet type hint. #12563

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 1 commit into from
Aug 21, 2024
Merged

Fix DatagramRequestHandler.packet type hint. #12563

merged 1 commit into from
Aug 21, 2024

Conversation

kmvanbrunt
Copy link
Contributor

Fixed DatagramRequestHandler.packet type hint to be bytes. typeshed is currently typing it as a socket.

In Python's stdlib, packet is set in the following code located in socketserver.py.

class DatagramRequestHandler(BaseRequestHandler):

    """Define self.rfile and self.wfile for datagram sockets."""

    def setup(self):
        from io import BytesIO
        self.packet, self.socket = self.request
        self.rfile = BytesIO(self.packet)
        self.wfile = BytesIO()

self.packet is the first element in the self.request tuple which is a typedshed._RequestType.

_RequestType: TypeAlias = _socket | tuple[bytes, _socket]

Additionally, in the setup() method shown above self.packet is being passed to BytesIO(), so it is definitely a bytes object.

Copy link
Contributor

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

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Thanks!

@srittau srittau merged commit 86e7416 into python:main Aug 21, 2024
63 checks passed
@kmvanbrunt kmvanbrunt deleted the fix/packet_type_bytes branch August 21, 2024 14:53
max-muoto pushed a commit to max-muoto/typeshed that referenced this pull request Sep 8, 2024
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