8000 This PR adds an API inspired by the standard library's cmd module. by yggdr · Pull Request #135 · aio-libs/aiomonitor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

This PR adds an API inspired by the standard library's cmd module. #135

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 6 commits into from
Sep 20, 2018

Conversation

yggdr
Copy link
Contributor
@yggdr yggdr commented Sep 2, 2018

No description provided.

@codecov
Copy link
codecov bot commented Sep 2, 2018

Codecov Report

Merging #135 into master will decrease coverage by 5.18%.
The diff coverage is 74.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
- Coverage      92%   86.81%   -5.19%     
==========================================
  Files           4        4              
  Lines         300      364      +64     
  Branches       39       48       +9     
==========================================
+ Hits          276      316      +40     
- Misses         16       35      +19     
- Partials        8       13       +5
Impacted Files Coverage Δ
aiomonitor/utils.py 94.93% <100%> (-0.25%) ⬇️
aiomonitor/monitor.py 84.17% <74.43%> (-6.31%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 561a1e6...2be077d. Read the comment docs.

help_template = '{cmd_name} {arg_list}\n {doc}\n'
help_short_template = ' {cmd_name}{cmd_arg_sep}{arg_list}: {doc_firstline}' # noqa

_sin = None # type: IO[str]
Copy link
Member

Choose a reason for hiding this comment

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

probably Optional[IO[str]]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This gave me problems further down the road, where mypy does not realise that within the do_* methods, _sout is guaranteed to be set to an instance of IO[str], so it errors out because None doesn't have a write method.

8000
@@ -141,6 +153,72 @@ def _server(self) -> None:
except (socket.timeout, OSError):
continue

def _interactive_loop(self, sin: IO[str], sout: IO[str]) -> None:
"""Main interactive loop of the monitor"""
self._sin = sin
Copy link
Member

Choose a reason for hiding this comment

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

why do we need expose self._sin at class level?

Copy link
Member

Choose a reason for hiding this comment

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

just to avoid do_where(self, sin: IO[str], sout: IO[str], taskid: int) having extra agrs? How we can ensure that _sin/_sout are set? may be add check in _command_dispatch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, avoiding passing the same IO arguments everywhere was the idea.

Given how the Monitor class is structured, the do_* methods are only called from within _command_dispatch, which itself is only called from within a running _interactive_loop. This loop sets the IO attributes at the beginning, and unsets them in the finally clause at the end. So they are guaranteed to be set for do_* methods.

If you dislike this, I'm open to reverting this.

if str(param).startswith('*'):
yield from (type_(arg) for arg in ia) # type: ignore
else:
yield type_(next(ia)) # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

we expect StopIteration only here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We iterate over the functions annotation for its parameters. Within that, we manually iterate over the given arguments (with the ia = iter(args) and next(ia) construct; I don't use zip since those two sequences may have arbitrary length difference). Now, when when we are in the else clause of the if (meaning we have not yet reached *args), we could be in the situation where a further parameter exists, but no argument is given to that parameter. Since we might have do_* methods with optional, non-star arguments, we must ignore a StopIteration from this call to next.
I probably should add this as a comment to the code.

yield from (type_(arg) for arg in ia) # type: ignore
else:
yield type_(next(ia)) # type: ignore
except StopIteration:
Copy link
Member

Choose a reason for hiding this comment

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

Lets use contextlib.suppress instead except StopIteration: pass, looks a bit nicer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, How could I have overlooked the suppress for this case :)

Add clarification comment

Add missing typing
Copy link
8000
Member
@jettify jettify left a comment

Choose a reason for hiding this comment

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

thanks a lot!

@jettify jettify merged commit 230a351 into aio-libs:master Sep 20, 2018
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
0