mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
ensure dict keys are hashable
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Fix a bug that function calls in ``setup.py`` can't be parsed rightly.
|
||||
+10
-1
@@ -992,6 +992,15 @@ class Analyzer(ast.NodeVisitor):
|
||||
return setup
|
||||
|
||||
|
||||
def _ensure_hashable(item):
|
||||
try:
|
||||
hash(item)
|
||||
except TypeError:
|
||||
return str(item)
|
||||
else:
|
||||
return item
|
||||
|
||||
|
||||
def ast_unparse(item, initial_mapping=False, analyzer=None, recurse=True): # noqa:C901
|
||||
# type: (Any, bool, Optional[Analyzer], bool) -> Union[List[Any], Dict[Any, Any], Tuple[Any, ...], STRING_TYPE]
|
||||
unparse = partial(
|
||||
@@ -1003,7 +1012,7 @@ def ast_unparse(item, initial_mapping=False, analyzer=None, recurse=True): # no
|
||||
constant = ast.Ellipsis
|
||||
unparsed = item
|
||||
if isinstance(item, ast.Dict):
|
||||
unparsed = dict(zip(unparse(item.keys), unparse(item.values)))
|
||||
unparsed = dict(zip(map(_ensure_hashable, unparse(item.keys)), unparse(item.values)))
|
||||
elif isinstance(item, ast.List):
|
||||
unparsed = [unparse(el) for el in item.elts]
|
||||
elif isinstance(item, ast.Tuple):
|
||||
|
||||
Reference in New Issue
Block a user