Skip to content

Commit

Permalink
Add ast.Bytes in typing_classes _unparse
Browse files Browse the repository at this point in the history
Fix "NotImplementedError: Constant(value=*)"
when defining TypedDict in alternative syntax
with literal bytes values.
  • Loading branch information
danialkeimasi authored and asottile committed Sep 15, 2022
1 parent 1fd0dfa commit 522c6cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyupgrade/_plugins/typing_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _unparse(node: ast.expr) -> str:
else:
slice_s = _unparse(node_slice)
return f'{_unparse(node.value)}[{slice_s}]'
elif isinstance(node, ast.Str):
elif isinstance(node, (ast.Str, ast.Bytes)):
return repr(node.s)
elif isinstance(node, ast.Ellipsis):
return '...'
Expand Down
10 changes: 10 additions & 0 deletions tests/features/typing_classes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ def test_typing_typed_dict_noop(s):
id='TypedDict from dict literal',
),
pytest.param(
'import typing\n'
'D = typing.TypedDict("D", {"a": typing.Literal["b", b"c"]})\n',
'import typing\n'
'class D(typing.TypedDict):\n'
" a: typing.Literal['b', b'c']\n",
id='with Literal of bytes',
),
pytest.param(
'import typing\n'
'D = typing.TypedDict("D", {"a": int}, total=False)\n',
Expand Down

0 comments on commit 522c6cd

Please sign in to comment.