Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotImplementedError on optional TypedDict union in functional definition #766

Closed
kkirsche opened this issue Dec 6, 2022 · 1 comment · Fixed by #767
Closed

NotImplementedError on optional TypedDict union in functional definition #766

kkirsche opened this issue Dec 6, 2022 · 1 comment · Fixed by #767

Comments

@kkirsche
Copy link

kkirsche commented Dec 6, 2022

Traceback (most recent call last):
  File "/Users/v832272/.asdf/installs/python/3.11.0/bin/pyupgrade", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/v832272/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/pyupgrade/_main.py", line 381, in main
    ret |= _fix_file(filename, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/v832272/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/pyupgrade/_main.py", line 318, in _fix_file
    contents_text = _fix_plugins(
                    ^^^^^^^^^^^^^
  File "/Users/v832272/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/pyupgrade/_main.py", line 80, in _fix_plugins
    callback(i, tokens)
  File "/Users/v832272/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/pyupgrade/_plugins/typing_classes.py", line 141, in _fix_dict_typed_dict
    end, attrs = _typed_class_replacement(tokens, i, call, types)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/v832272/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/pyupgrade/_plugins/typing_classes.py", line 82, in _typed_class_replacement
    member = f'{indent}{k}: {_unparse(v)}'
                             ^^^^^^^^^^^
  File "/Users/v832272/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/pyupgrade/_plugins/typing_classes.py", line 50, in _unparse
    raise NotImplementedError(ast.dump(node))
NotImplementedError: BinOp(left=Name(id='ExampleChangeRequestResponseOutageDict', ctx=Load()), op=BitOr(), right=Constant(value=None))

This is triggered by:

ExampleChangeRequestResponseOutageDict = TypedDict(
    "ExampleChangeRequestResponseOutageDict",
    {"outage-seq-id": int, "outage-start-time": str, "outage-end-time": str},
)

ExampleChangeRequestResponseOutageListDict = TypedDict(
    "ExampleChangeRequestResponseOutageListDict",
    {"outages": ExampleChangeRequestResponseOutageDict | None},
)

Command used:

find src -name '*.py' -type f | xargs -n 1 -I {} pyupgrade --py311-plus {}
@asottile
Copy link
Owner

asottile commented Dec 6, 2022

ah yes, the binary or syntax came way after this rewrite -- should be an easy patch though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants