Skip to content

Commit

Permalink
Fix #53: crash in RewriteEmptyContainers.
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Jan 11, 2018
1 parent d35f3e9 commit 13de516
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
master
------

* Fix crash in RewriteEmptyContainers rewriter if a parameter has only empty
container types in traces (and more than one). Fixes #53.


18.1.10
-------
Expand Down
4 changes: 3 additions & 1 deletion monkeytype/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ def _is_empty(self, typ):
def rewrite_Union(self, union):
elems = tuple(
self.rewrite(e) for e in union.__args__ if not self._is_empty(e))
return Union[elems]
if elems:
return Union[elems]
return union


class RewriteConfigDict(TypeRewriter):
Expand Down
1 change: 1 addition & 0 deletions tests/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TestRemoveEmptyContainers:
),
(Union[str, int], Union[str, int]),
(Dict[str, Union[List[str], List[Any]]], Dict[str, List[str]]),
(Union[List[Any], Set[Any]], Union[List[Any], Set[Any]])
],
)
def test_rewrite(self, typ, expected):
Expand Down

0 comments on commit 13de516

Please sign in to comment.