Skip to content

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

Merged
1st1 merged 3 commits into
python:masterfrom
1st1:fix_reader_check
Nov 13, 2017
Merged

bpo-28369: Enhance transport socket check in add_reader/writer#4365
1st1 merged 3 commits into
python:masterfrom
1st1:fix_reader_check

Conversation

@1st1

@1st1 1st1 commented Nov 10, 2017

Copy link
Copy Markdown
Member

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

1st1 commented Nov 13, 2017

Copy link
Copy Markdown
Member Author

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

@asvetlov asvetlov left a comment

Copy link
Copy Markdown
Contributor

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.

self.call_exception_handler(context)

def _ensure_fd_no_transport(self, fd):
fileno = fd

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it, sorry.

Comment thread Lib/asyncio/selector_events.py Outdated
try:
fileno = int(fileno.fileno())
except (AttributeError, TypeError, ValueError):
# This code matches `selectors._fileobj_to_fd` function.

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread Lib/asyncio/test_utils.py Outdated
try:
fd = int(fd.fileno())
except (AttributeError, TypeError, ValueError):
# This code matches `selectors._fileobj_to_fd` function.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread Lib/asyncio/test_utils.py
def _ensure_fd_no_transport(self, fd):
if not isinstance(fd, int):
try:
fd = int(fd.fileno())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not covered

Comment thread Lib/asyncio/test_utils.py
fd = int(fd.fileno())
except (AttributeError, TypeError, ValueError):
# This code matches `selectors._fileobj_to_fd` function.
raise ValueError("Invalid file object: "

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

1st1 commented Nov 13, 2017

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

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

@asvetlov asvetlov left a comment

Copy link
Copy Markdown
Contributor

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

1st1 commented Nov 13, 2017

Copy link
Copy Markdown
Member Author

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