Skip to content

Commit 48d9823

Browse files
drallensmithpitrou
authored andcommitted
bpo-5001, bpo-31169: Fix two uninformative asserts in multiprocessing/managers.py (#3078)
* Make error message more informative Replace assertions in error-reporting code with more-informative version that doesn't cause confusion over where and what the error is. * Additional clarification + get travis to check * Change from SystemError to TypeError As suggested in PR comment by @pitrou, changing from SystemError; TypeError appears appropriate. * NEWS file installation; ACKS addition (will do my best to justify it by additional work)
1 parent e664d7f commit 48d9823

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Lib/multiprocessing/managers.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ def dispatch(c, id, methodname, args=(), kwds={}):
8484
def convert_to_error(kind, result):
8585
if kind == '#ERROR':
8686
return result
87-
elif kind == '#TRACEBACK':
88-
assert type(result) is str
89-
return RemoteError(result)
90-
elif kind == '#UNSERIALIZABLE':
91-
assert type(result) is str
92-
return RemoteError('Unserializable message: %s\n' % result)
87+
elif kind in ('#TRACEBACK', '#UNSERIALIZABLE'):
88+
if not isinstance(result, str):
89+
raise TypeError(
90+
"Result {0!r} (kind '{1}') type is {2}, not str".format(
91+
result, kind, type(result)))
92+
if kind == '#UNSERIALIZABLE':
93+
return RemoteError('Unserializable message: %s\n' % result)
94+
else:
95+
return RemoteError(result)
9396
else:
94-
return ValueError('Unrecognized message type')
97+
return ValueError('Unrecognized message type {!r}'.format(kind))
9598

9699
class RemoteError(Exception):
97100
def __str__(self):

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,7 @@ Ville Skyttä
14651465
Michael Sloan
14661466
Nick Sloan
14671467
Václav Šmilauer
1468+
Allen W. Smith
14681469
Christopher Smith
14691470
Eric V. Smith
14701471
Gregory P. Smith
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
There are a number of uninformative asserts in the `multiprocessing` module,
2+
as noted in issue 5001. This change fixes two of the most potentially
3+
problematic ones, since they are in error-reporting code, in the
4+
`multiprocessing.managers.convert_to_error` function. (It also makes more
5+
informative a ValueError message.) The only potentially problematic change
6+
is that the AssertionError is now a TypeError; however, this should also
7+
help distinguish it from an AssertionError being *reported* by the
8+
function/its caller (such as in issue 31169). - Patch by Allen W. Smith
9+
(drallensmith on github).

0 commit comments

Comments
 (0)