-
Notifications
You must be signed in to change notification settings - Fork 126
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
Avoid cyclic dependency by merging callers.py into hooks.py #227
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import sys | ||
import warnings | ||
|
||
|
||
if sys.version_info < (3,): | ||
exec( | ||
""" | ||
def _reraise(cls, val, tb): | ||
raise cls, val, tb | ||
""" | ||
) | ||
|
||
|
||
class _Result(object): | ||
def __init__(self, result, excinfo): | ||
self._result = result | ||
self._excinfo = excinfo | ||
|
||
@property | ||
def excinfo(self): | ||
return self._excinfo | ||
|
||
@property | ||
def result(self): | ||
"""Get the result(s) for this hook call (DEPRECATED in favor of ``get_result()``).""" | ||
msg = "Use get_result() which forces correct exception handling" | ||
warnings.warn(DeprecationWarning(msg), stacklevel=2) | ||
return self._result | ||
|
||
@classmethod | ||
def from_call(cls, func): | ||
__tracebackhide__ = True | ||
result = excinfo = None | ||
try: | ||
result = func() | ||
except BaseException: | ||
excinfo = sys.exc_info() | ||
|
||
return cls(result, excinfo) | ||
|
||
def force_result(self, result): | ||
"""Force the result(s) to ``result``. | ||
|
||
If the hook was marked as a ``firstresult`` a single value should | ||
be set otherwise set a (modified) list of results. Any exceptions | ||
found during invocation will be deleted. | ||
""" | ||
self._result = result | ||
self._excinfo = None | ||
|
||
def get_result(self): | ||
"""Get the result(s) for this hook call. | ||
|
||
If the hook was marked as a ``firstresult`` only a single value | ||
will be returned otherwise a list of results. | ||
""" | ||
__tracebackhide__ = True | ||
if self._excinfo is None: | ||
return self._result | ||
else: | ||
ex = self._excinfo | ||
if sys.version_info >= (3,): | ||
raise ex[1].with_traceback(ex[2]) | ||
_reraise(*ex) # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
""" | ||
Tracing utils | ||
""" | ||
from .callers import _Result | ||
from ._result import _Result | ||
|
||
|
||
class TagTracer(object): | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Yeah I'm not huge on moving big chunks like this since we lose attribution from the original author in git (unless that's been addressed in recent versions).
I am guilty of this when creating this file (which was an attempt to breakout caller implementations into a separate namespace - see comment below). I really would have liked to have kept @hpk42's original attribution here..