Skip to content

TypeError: unhashable type errors in filter_unused_variable #325

@gabe-sherman

Description

@gabe-sherman

The below code triggers an unhashable type error when calling filter_unused_variable. This occurs in 'is_literal_or_name' at line 788 in autoflake.py.

import autoflake
autoflake.filter_unused_variable("g={{}}") # TypeError: unhashable type: 'dict'
autoflake.filter_unused_variable("g={[\n]}") # TypeError: unhashable type: 'list'

Setup Info

Version: 2.31
Commit: b87ff10

Trace Report For Each Input

Traceback (most recent call last):
  File "rep.py", line 4, in <module>
    autoflake.filter_unused_variable("g={[\n]}")
  File "python3.10/site-packages/autoflake.py", line 731, in filter_unused_variable
    if is_literal_or_name(value):
  File "python3.10/site-packages/autoflake.py", line 788, in is_literal_or_name
    ast.literal_eval(value)
  File "python3.10/ast.py", line 110, in literal_eval
    return _convert(node_or_string)
  File "python3.10/ast.py", line 92, in _convert
    return set(map(_convert, node.elts))
TypeError: unhashable type: 'dict'
Traceback (most recent call last):
  File "rep.py", line 4, in <module>
    autoflake.filter_unused_variable("g={[\n]}")
  File "python3.10/site-packages/autoflake.py", line 731, in filter_unused_variable
    if is_literal_or_name(value):
  File "python3.10/site-packages/autoflake.py", line 788, in is_literal_or_name
    ast.literal_eval(value)
  File "python3.10/ast.py", line 110, in literal_eval
    return _convert(node_or_string)
  File "python3.10/ast.py", line 92, in _convert
    return set(map(_convert, node.elts))
TypeError: unhashable type: 'list'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions