Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@fourdim
Copy link
Contributor

@fourdim fourdim commented Jun 30, 2025

No description provided.

def patch_except(path: Optional[Union[str, Callable[[], str]]] = None,
directory: Optional[str] = None):
directory: Optional[str] = None,
exclude: Optional[List[BaseException]] = None):
Copy link
Owner

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.

Copy link
Contributor Author

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.

@fourdim
Copy link
Contributor Author

fourdim commented Sep 4, 2025

@gaogaotiantian ping

''.join(traceback.format_exception(type, value, tb)).strip()])

def _excepthook(type, value, tb):
if _exclude is not None and isinstance(value, _exclude):
Copy link
Owner

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.

Copy link
Contributor Author

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

codecov bot commented Nov 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3aee822) to head (10cbefa).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

_exclude = tuple()
if exclude is not None:
_exclude = tuple(exclude)
if any((not issubclass(excCls, BaseException)) for excCls in _exclude):
Copy link
Owner

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().

@gaogaotiantian
Copy link
Owner

Could you rebase/merge master as I just fixed the lint issue. Also take a look at the coverage miss. Thanks!

@fourdim fourdim force-pushed the exclude branch 2 times, most recently from ea10a4b to 874c739 Compare November 2, 2025 19:56
@fourdim
Copy link
Contributor Author

fourdim commented Nov 2, 2025

Now should have the full coverage.

@gaogaotiantian
Copy link
Owner

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.

@fourdim
Copy link
Contributor Author

fourdim commented Nov 2, 2025

It is weird. I initially tested with the program in test_except_exclude, that path is not covered (not executing the print statement I inserted, no dump). But after realizing the failed test, I revert back from type to value. That path is covered again.

@fourdim
Copy link
Contributor Author

fourdim commented Nov 2, 2025

@gaogaotiantian
Copy link
Owner

Why do you need the support for NTSTATUS?

I don't think you need a custom exception, just use ValueError or something. It's confusing to have an unnecessary exception.

type and value are different things. If you can mix them up and the test can still pass, there's something wrong with the test I think.

@fourdim
Copy link
Contributor Author

fourdim commented Nov 2, 2025

Apparently I cannot. It is just I didn't test it after changing value to type. And it indeed did not pass the CI as well.
The thing is the patch that gens the initial code coverage gives 77% is using value (the correct one), but the path is covered when I am testing locally.
And if you monitored the progress of CI. The codecov gives 77% first and then 100%. Meaning in multiple CI runs, some are covering that two lines, some are not.

@gaogaotiantian
Copy link
Owner

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.

@gaogaotiantian
Copy link
Owner

You need to change your validation code :)

@gaogaotiantian
Copy link
Owner

I would recommend run make test locally before push the code - it is pretty fast.

@fourdim
Copy link
Contributor Author

fourdim commented Nov 2, 2025

I would recommend run make test locally before push the code - it is pretty fast.

Will do.


from .coredumpy import dump


Copy link
Owner

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.

Copy link
Contributor Author

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.

@gaogaotiantian gaogaotiantian merged commit 4f54f78 into gaogaotiantian:master Nov 3, 2025
26 checks passed
@gaogaotiantian
Copy link
Owner

Thank you for the contribution!

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