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

Embedded TypedDict produces AST error on Python 3.10 #804

Open
Andrew-Chen-Wang opened this issue Mar 11, 2023 · 0 comments
Open

Embedded TypedDict produces AST error on Python 3.10 #804

Andrew-Chen-Wang opened this issue Mar 11, 2023 · 0 comments

Comments

@Andrew-Chen-Wang
Copy link

Bug in TypedDict AST parsing running on Python 3.10. Runs fine during running of Python application/web server with no output. Black and isort formatting doesn't have a problem either. Example code:

CycleT = TypedDict(
    "CycleT",
    {
        "query": list[
            TypedDict(
                "query",
                {
                    "branches": list[
                        TypedDict(
                            "branches",
                            {
                                "branches": list[
                                    TypedDict(
                                        "branches",
                                        {
                                            "branches": list[
                                                TypedDict(
                                                    "branches",
                                                    {"count": int},
                                                )
                                            ]
                                        },
                                    )
                                ]
                            },
                        )
                    ]
                },
            )
        ],
    },
)

Pre-commit file

  - repo: https://github.com/asottile/pyupgrade
    rev: v3.3.1
    hooks:
      - id: pyupgrade
        args: ['--py310-plus', '--keep-mock']

Stacktrace

pyupgrade................................................................Failed
- hook id: pyupgrade
- exit code: 1

Traceback (most recent call last):
  File "/Users/andrewcwang/.cache/pre-commit/repoof0hoxn7/py_env-python3.10/bin/pyupgrade", line 8, in <module>
    sys.exit(main())
  File "/Users/andrewcwang/.cache/pre-commit/repoof0hoxn7/py_env-python3.10/lib/python3.10/site-packages/pyupgrade/_main.py", line 381, in main
    ret |= _fix_file(filename, args)
  File "/Users/andrewcwang/.cache/pre-commit/repoof0hoxn7/py_env-python3.10/lib/python3.10/site-packages/pyupgrade/_main.py", line 318, in _fix_file
    contents_text = _fix_plugins(
  File "/Users/andrewcwang/.cache/pre-commit/repoof0hoxn7/py_env-python3.10/lib/python3.10/site-packages/pyupgrade/_main.py", line 80, in _fix_plugins
    callback(i, tokens)
  File "/Users/andrewcwang/.cache/pre-commit/repoof0hoxn7/py_env-python3.10/lib/python3.10/site-packages/pyupgrade/_plugins/typing_classes.py", line 143, in _fix_dict_typed_dict
    end, attrs = _typed_class_replacement(tokens, i, call, types)
  File "/Users/andrewcwang/.cache/pre-commit/repoof0hoxn7/py_env-python3.10/lib/python3.10/site-packages/pyupgrade/_plugins/typing_classes.py", line 84, in _typed_class_replacement
    member = f'{indent}{k}: {_unparse(v)}'
  File "/Users/andrewcwang/.cache/pre-commit/repoof0hoxn7/py_env-python3.10/lib/python3.10/site-packages/pyupgrade/_plugins/typing_classes.py", line 39, in _unparse
    slice_s = _unparse(node_slice)
  File "/Users/andrewcwang/.cache/pre-commit/repoof0hoxn7/py_env-python3.10/lib/python3.10/site-packages/pyupgrade/_plugins/typing_classes.py", line 52, in _unparse
    raise NotImplementedError(ast.dump(node))
NotImplementedError: Call(func=Name(id='TypedDict', ctx=Load()), args=[Constant(value='query'), Dict(keys=[Constant(value='branches')], values=[Subscript(value=Name(id='list', ctx=Load()), slice=Call(func=Name(id='TypedDict', ctx=Load()), args=[Constant(value='branches'), Dict(keys=[Constant(value='branches')], values=[Subscript(value=Name(id='list', ctx=Load()), slice=Call(func=Name(id='TypedDict', ctx=Load()), args=[Constant(value='branches'), Dict(keys=[Constant(value='branches')], values=[Subscript(value=Name(id='list', ctx=Load()), slice=Call(func=Name(id='TypedDict', ctx=Load()), args=[Constant(value='branches'), Dict(keys=[Constant(value='count')], values=[Name(id='int', ctx=Load())])], keywords=[]), ctx=Load())])], keywords=[]), ctx=Load())])], keywords=[]), ctx=Load())])], keywords=[])
@Andrew-Chen-Wang Andrew-Chen-Wang changed the title Cyclical TypedDict produces AST error on Python 3.10 Embedded TypedDict produces AST error on Python 3.10 Mar 11, 2023
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

No branches or pull requests

1 participant