From 0b0002c8c6773702fd01f1b590b18c483dcaa5ad Mon Sep 17 00:00:00 2001 From: Ram Rachum Date: Thu, 8 Dec 2022 19:50:39 +0200 Subject: [PATCH] Fix exception causes in introspect/type_parsing.py --- introspect/type_parsing.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/introspect/type_parsing.py b/introspect/type_parsing.py index 612708fb..dfa535e7 100644 --- a/introspect/type_parsing.py +++ b/introspect/type_parsing.py @@ -128,15 +128,16 @@ def parse_type( """Parses a string that represents a C type into an AST node.""" try: type_str_stack = _peel_nested_parens(type_name.strip()) - except AssertionError: - raise ValueError(f'{type_name!r} contains incorrectly nested parentheses') + except AssertionError as e: + raise ValueError(f'{type_name!r} contains incorrectly nested ' + f'parentheses') from e result = None while type_str_stack: try: result = _parse_maybe_array(type_str_stack.pop(), result) - except AssertionError: - raise ValueError(f'invalid type name {type_name!r}') + except AssertionError as e: + raise ValueError(f'invalid type name {type_name!r}') from e assert result # hint for pytype that `result` isn't None return result