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

_TimedContextManagerDecorator enter -> self #147

Merged
merged 3 commits into from
Aug 24, 2016

Conversation

ross
Copy link
Contributor

@ross ross commented Aug 8, 2016

Have _TimedContextManagerDecorator return self from __enter__ so that it can be modified within the block. e.g.

with timed('foo.bar', tags=['key:val']) as timer:
    # do some stuff
    if blip:
       timer.tags.append('result:blip')

This can be worked around by assigning timed's result to a var and then doing a with timer, but this is much cleaner and shouldn't result in any backwards compatibility issues.

Have _TimedContextManagerDecorator return self from __enter__ so that it can
be modified within the block. e.g.

with timed('foo.bar', tags=['key:val']) as timer:
    # do some stuff
    if blip:
       timer.tags.append('result:blip')

This can be worked around by assigning timed's result to a var and then
doing a `with timer`, but this is much cleaner.
@yannmh
Copy link
Member

yannmh commented Aug 22, 2016

Thanks for the change @ross.

I'll review the changes this week, and have it out with the next release by the end of the following week 🚢 .

@yannmh yannmh self-assigned this Aug 22, 2016
@yannmh yannmh added this to the 0.13.0 milestone Aug 22, 2016
@@ -313,7 +313,9 @@ def test_timed_context(self):
Measure the distribution of a context's run time.
"""
# In seconds
with self.statsd.timed('timed_context.test'):
with self.statsd.timed('timed_context.test') as timer:
self.assertIsInstance(timer,
Copy link
Member

Choose a reason for hiding this comment

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

I need to update the tests to inherit from unittest. In the meantime would you mind using

t.assert_is_instance(...)

rather than

self.assertIsIstance(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

Almost 😄 it should be t.assert... rather than self.assert...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. I've haven't run across nose.tools being used before. Should be in place now.

@yannmh
Copy link
Member

yannmh commented Aug 24, 2016

🙇

@yannmh yannmh merged commit be01e58 into DataDog:master Aug 24, 2016
@ross ross deleted the timed-context-self branch August 24, 2016 15:43
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