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

adjusting socketserver.BaseServer #13082

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

tungol
Copy link
Contributor

@tungol tungol commented Nov 24, 2024

This one might be a bad idea. fileno, get_request, and server_bind are documented to exist on BaseServer, but they don't. Of these, only get_request is actually called from the existing implementation of BaseServer (as part of handle_request and serve_forever).

In the ideal case, they'd probably all be abstract methods in CPython.

This one might be a bad idea. fileno, get_request, and server_bind
are documented to exist on BaseServer, but they don't. Of these,
only get_request is actually called from the existing implementation
of BaseServer (as part of handle_request and serve_forever).

In the ideal case, they'd probably all be abstract methods in
CPython.
@tungol tungol changed the title adjusting socketserver.BaseServer adjusting socketserver.BaseServer Nov 24, 2024

This comment has been minimized.

@tungol
Copy link
Contributor Author

tungol commented Nov 24, 2024

No mypy primer hits, but I'm not convinced that means this is the right thing to do.

@tungol
Copy link
Contributor Author

tungol commented Nov 24, 2024

I opened a CPython issue about it: python/cpython#127209

@tungol tungol marked this pull request as draft November 24, 2024 01:03
@tungol
Copy link
Contributor Author

tungol commented Nov 24, 2024

I could also try making them abstract in the stubs, even if CPython doesn't.

This comment has been minimized.

@tungol tungol closed this Dec 12, 2024
@JelleZijlstra
Copy link
Member

Any specific reason to close this? I haven't been very on top of reviewing typeshed PRs (lots of other things keeping me busy) but I do intend to get back to them.

@tungol
Copy link
Contributor Author

tungol commented Dec 12, 2024

Yeah, this one has been sitting in draft because I kind of intend to pursue python/cpython#127209 first and see where that goes. This had merge conflicts again, and since I didn't intend to take it out of draft anytime soon I decided to close it instead of fix the merge conflict. I'll get back to it at some point, but I didn't feel great about this particular solution.

@tungol tungol reopened this Dec 15, 2024
@tungol tungol marked this pull request as ready for review December 15, 2024 22:36

This comment has been minimized.

@tungol
Copy link
Contributor Author

tungol commented Dec 15, 2024

Okay, I'm ready to re-open this now. I have an MR out at CPython which this aligns with: python/cpython#127976

The one thing we might want to do differently here in typeshed is that the socket attribute is used by BaseServer.handle_request right now. I think that's a mistake, and my MR would change that, but right now a subclass of BaseServer which doesn't create a socket attribute for itself is not going to work. I moved it to TCPServer here anyway, but it'd also be reasonable to keep socket as an attribute of BaseServer until that fix is available.

I was thinking it wasn't useful to lie about the existence of BaseServer.get_request, but then I realized it probably allows mypy to flag if a child class implements it with the wrong signature. That's enough of a benefit to keep it around. Assuming my other MR is accepted, it'll stop being a lie eventually.

This comment has been minimized.

Copy link
Contributor

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

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