Skip to content

Fix TypeError in is_literal_or_name on unhashable set literals#339

Merged
fsouza merged 1 commit intoPyCQA:mainfrom
worksbyfriday:fix-is-literal-or-name-typeerror
Feb 18, 2026
Merged

Fix TypeError in is_literal_or_name on unhashable set literals#339
fsouza merged 1 commit intoPyCQA:mainfrom
worksbyfriday:fix-is-literal-or-name-typeerror

Conversation

@worksbyfriday
Copy link
Copy Markdown
Contributor

Summary

  • ast.literal_eval raises TypeError (not just SyntaxError/ValueError) when evaluating set literals containing unhashable types like dicts or lists (e.g., {{}}, {[]})
  • Adds TypeError to the existing except clause to prevent the crash

Fixes #325

Test plan

  • Added test for is_literal_or_name("{{}}}") and is_literal_or_name("{[]}") (should return False, not crash)
  • All 170 existing tests continue to pass

ast.literal_eval raises TypeError (not just SyntaxError/ValueError)
when evaluating set literals containing unhashable types like dicts
or lists. Catch TypeError as well to prevent the crash.

Fixes PyCQA#325

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@fsouza fsouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@fsouza fsouza merged commit e2109ba into PyCQA:main Feb 18, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: unhashable type errors in filter_unused_variable

2 participants