-
Notifications
You must be signed in to change notification settings - Fork 20
Support exclude in coredumpy.patch_except #88
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
Conversation
src/coredumpy/except_hook.py
Outdated
| def patch_except(path: Optional[Union[str, Callable[[], str]]] = None, | ||
| directory: Optional[str] = None): | ||
| directory: Optional[str] = None, | ||
| exclude: Optional[List[BaseException]] = None): |
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.
Let's use Sequence rather than List here for type hint. You are converting it to tuple and there's no reason to force it to be a list. Also Exception might be better here because I don't believe SystemExit is caught on sys.excepthook.
An alternative to Sequence is just tuple - immutable is a good thing. You are lazy evaluating this and if it's mutable, it could be changed unexpectedly.
Also, do some sanity check for the argument. We want error out early if what user passes is wrong, not wait until it is evaluated.
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.
I use Iterable instead and make it immutable internally.
KeyboardInterrupt is a subclass of BaseException but not Exception. I believe that most use case for this exclude will be KeyboardInterrupt, so I preserve it there.
PTAL.
|
@gaogaotiantian ping |
src/coredumpy/except_hook.py
Outdated
| ''.join(traceback.format_exception(type, value, tb)).strip()]) | ||
|
|
||
| def _excepthook(type, value, tb): | ||
| if _exclude is not None and isinstance(value, _exclude): |
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.
Just came back from the trip so I can take a look at the PR. Is this correct? _exclude is a tuple right? _exclude is already internal we don't have to make it default to None. We can enforce _exclude to be a tuple and use empty tuple for no exclusion. So you don't need to check None here.
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.
Addressed and also updated to the correct type hint
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #88 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 18
Lines 1196 1204 +8
=========================================
+ Hits 1196 1204 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/coredumpy/except_hook.py
Outdated
| _exclude = tuple() | ||
| if exclude is not None: | ||
| _exclude = tuple(exclude) | ||
| if any((not issubclass(excCls, BaseException)) for excCls in _exclude): |
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.
Do you need the parenthesis around not issubclass(excCls, BaseException)? It looks unnecessary.
Here I probably prefer an else case for _exclude = tuple().
|
Could you rebase/merge |
ea10a4b to
874c739
Compare
|
Now should have the full coverage. |
|
I would suggest not using force-push when you don't have to (unless if you rebased the branch). It's easier to keep track of the commit history on the branch. All the commits will be squashed anyway. |
|
It is weird. I initially tested with the program in |
|
Can I modify the test infra to add support for https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55 ? |
|
Why do you need the support for NTSTATUS? I don't think you need a custom exception, just use
|
|
Apparently I cannot. It is just I didn't test it after changing |
|
You need to wait for the CI to finish. There are platform specific code. I think you can check the detailed coverage in the codecov report, but as long as the lines are covered eventually it's okay. |
|
You need to change your validation code :) |
|
I would recommend run |
Will do. |
|
|
||
| from .coredumpy import dump | ||
|
|
||
|
|
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.
Last thing, why did you remove this blank line? Let's try to avoid the cosmetic changes.
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.
I didn't notice. It might be when adding the from typing import type, the formatter automatically intervenes. Reverting.
|
Thank you for the contribution! |
No description provided.