Skip to content

bpo-28369: Enhance transport socket check in add_reader/writer #4365

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 3 commits into from
Nov 13, 2017

Conversation

1st1
Copy link
Member

@1st1 1st1 commented Nov 10, 2017

https://bugs.python.org/issue28369

Original PR python/asyncio#420 missed the fact that loop.add_reader and loop.add_writer accept file-like objects in addition to int FDs.

@1st1
Copy link
Member Author

1st1 commented Nov 13, 2017

@asvetlov Andrew, could you please take a look at this one?

Copy link
Contributor

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

Thanks for PR.
Please fix notes.

I suggest installing codecov browser extension: https://docs.codecov.io/v4.3.6/docs/browser-extension

You'll see uncovered red lines just in Files changed tab on gihub.

@@ -246,8 +246,16 @@ def _accept_connection2(self, protocol_factory, conn, extra,
self.call_exception_handler(context)

def _ensure_fd_no_transport(self, fd):
fileno = fd
Copy link
Contributor

Choose a reason for hiding this comment

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

Please not make a new fileno local variable but reuse fd in the rest of function -- like selectors._fileobj_to_fd does.

Copy link
Member Author

Choose a reason for hiding this comment

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

fd is used later in this function to format a better error message. This is not a copy/paste of selectors._fileobj_to_fd.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, sorry.

try:
fileno = int(fileno.fileno())
except (AttributeError, TypeError, ValueError):
# This code matches `selectors._fileobj_to_fd` function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid backticks -- without them the comment is still pretty clean.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed, but this is a very personal preference -- for me it was easier to read that comment with backticks/quotes.

try:
fd = int(fd.fileno())
except (AttributeError, TypeError, ValueError):
# This code matches `selectors._fileobj_to_fd` function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid backticks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

Choose a reason for hiding this comment

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

@1st1 I hate any complex markup in comments, selectors._fileobj_to_fd without backticks is still pretty readable and understandable.
This is just my opinion.
But if you want to keep them -- I can live with it. Very minor thing about a taste.

fileno = int(fileno.fileno())
except (AttributeError, TypeError, ValueError):
# This code matches `selectors._fileobj_to_fd` function.
raise ValueError("Invalid file object: "
Copy link
Contributor

Choose a reason for hiding this comment

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

Not covered by tests

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a functional test for this.

@@ -361,6 +361,13 @@ def assert_writer(self, fd, callback, *args):
handle._args, args)

def _ensure_fd_no_transport(self, fd):
if not isinstance(fd, int):
try:
fd = int(fd.fileno())
Copy link
Contributor

Choose a reason for hiding this comment

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

Not covered

fd = int(fd.fileno())
except (AttributeError, TypeError, ValueError):
# This code matches `selectors._fileobj_to_fd` function.
raise ValueError("Invalid file object: "
Copy link
Contributor

Choose a reason for hiding this comment

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

Not covered.

Copy link
Member Author

Choose a reason for hiding this comment

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

This won't be covered as it's test_utils' test loop. There's no point in covering it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe let's add # pragma: no cover comment for except clause?
It increases formal coverage level at least (:

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@1st1
Copy link
Member Author

1st1 commented Nov 13, 2017

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@asvetlov: please review the changes made to this pull request.

Copy link
Contributor

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

Sorry for my censoriousness.

@1st1
Copy link
Member Author

1st1 commented Nov 13, 2017

Thanks, Andrew!

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.

4 participants