[WIP] bpo-39725: Suppress only handled exception by "raise ... from ...".#18629
[WIP] bpo-39725: Suppress only handled exception by "raise ... from ...".#18629serhiy-storchaka wants to merge 1 commit intopython:mainfrom
Conversation
| def _report_invalid_netmask(cls, netmask_str, suppress=True): | ||
| msg = '%r is not a valid netmask' % netmask_str | ||
| raise NetmaskValueError(msg) from None | ||
| if suppress: |
There was a problem hiding this comment.
In some cases there is no other exception to suppress. When we call this function not from the except block.
There was a problem hiding this comment.
You can check whether sys.exception() is None.
There was a problem hiding this comment.
Though, do you need to? What's the harm in "from None" when you are not in an except block?
| # Check for a netmask or hostmask in dotted-quad form. | ||
| # This may raise NetmaskValueError. | ||
| prefixlen = cls._prefix_from_ip_string(arg) | ||
| prefixlen = cls._prefix_from_string(arg) |
There was a problem hiding this comment.
It was moved to a separate function because it is hard to write it correctly without return. Otherwise we would need to write something like (not tested):
try:
prefixlen = cls._prefix_from_prefix_string(arg)
except NetmaskValueError:
try:
prefixlen = cls._prefix_from_ip_string(arg)
except BaseException as exc:
raise exc from None|
@serhiy-storchaka Are you sure you got the bpo issue right? Looks unrelated to me. |
|
You are right. I copied it from a wrong issue. |
Codecov Report
@@ Coverage Diff @@
## master #18629 +/- ##
========================================
Coverage 82.06% 82.07%
========================================
Files 1955 1955
Lines 584068 584254 +186
Branches 44458 44460 +2
========================================
+ Hits 479334 479525 +191
+ Misses 95110 95103 -7
- Partials 9624 9626 +2
Continue to review full report at Codecov.
|
https://bugs.python.org/issue39725