-
-
Notifications
You must be signed in to change notification settings - Fork 378
Fix trio.socket.SocketType.bind to work with PathLike arguments again #3042
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3042 +/- ##
=======================================
Coverage 99.63% 99.63%
=======================================
Files 120 121 +1
Lines 17832 17841 +9
Branches 3204 3206 +2
=======================================
+ Hits 17767 17776 +9
Misses 46 46
Partials 19 19
|
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.
Could you add a regression test? I'm not sure exactly how to, but it's probably fine to use a tmpfile as a socket and actually do the IO.
EDIT: it looks like we test open_unix_socket already, maybe just make the name types a 2x2 parametrized thing? (not sure about keeping it in test_highlevel_open_unix_stream but honestly it's either that or test_socket and that's better.)
trio/src/trio/_tests/test_highlevel_open_unix_stream.py
Lines 54 to 76 in 20f9291
| async def test_open_unix_socket() -> None: | |
| for name_type in [Path, str]: | |
| name = tempfile.mktemp() | |
| serv_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
| with serv_sock: | |
| serv_sock.bind(name) | |
| try: | |
| serv_sock.listen(1) | |
| # The actual function we're testing | |
| unix_socket = await open_unix_socket(name_type(name)) | |
| async with unix_socket: | |
| client, _ = serv_sock.accept() | |
| with client: | |
| await unix_socket.send_all(b"test") | |
| assert client.recv(2048) == b"test" | |
| client.sendall(b"response") | |
| received = await unix_socket.receive_some(2048) | |
| assert received == b"response" | |
| finally: | |
| os.unlink(name) |
027a0be to
7a55d0e
Compare
|
pre-commit.ci autofix |
c14b7bc to
87a001f
Compare
It took a few tries but test is there and seems to pass. |
|
Why so many force pushes? |
|
Because I did not figure out how to successfully run the tests locally so it took me several tries to get the CI to pass. And I do not need to clutter commit history with trivial fixes of trivial mistakes. |
|
Not really an issue, we use squash and merge most of the time I think |
Was there any specific issues? We should make this better for new contributors. Was it just a matter of finding the right pytest invocation? |
A5rocks
left a comment
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.
Sorry, I keep forgetting: can you add a changelog entry? (A newsfragment)
|
@regnarg just a bump for this PR! |
|
Could someone else check the newsfragment looks fine? |
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.
Looks good to me.
import os
reveal_type(os.fspath)with mypy yields
note: Revealed type is "Overload(
def (path: builtins.str) -> builtins.str,
def (path: builtins.bytes) -> builtins.bytes,
def [AnyStr in (builtins.str, builtins.bytes)] (path: os.PathLike[AnyStr`-1]) -> AnyStr`-1
)"
so return is indeed str or bytes if pathlike is given
|
Hey @regnarg, it looks like that was the first time we merged one of your PRs! Thanks so much! 🎉 🎂 If you want to keep contributing, we'd love to have you. So, I just sent you an invitation to join the python-trio organization on Github! If you accept, then here's what will happen:
If you want to read more, here's the relevant section in our contributing guide. Alternatively, you're free to decline or ignore the invitation. You'll still be able to contribute as much or as little as you like, and I won't hassle you about joining again. But if you ever change your mind, just let us know and we'll send another invitation. We'd love to have you, but more importantly we want you to do whatever's best for you. If you have any questions, well... I am just a humble Python script, so I probably can't help. But please do post a comment here, or in our chat, or on our forum, whatever's easiest, and someone will help you out! |
fixes #3041