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

Bug: handling of arbitrary args and kwargs with type hints #163

Open
znicholls opened this issue Jan 8, 2024 · 1 comment
Open

Bug: handling of arbitrary args and kwargs with type hints #163

znicholls opened this issue Jan 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@znicholls
Copy link

Since PEP 484, it has been possible to have type hints on args and kwargs in a Python function e.g.

def test_func(some_arg: float, *args: str, **kwargs: int) -> bool:
    ...

At the moment, neogen's Python configuration doesn't seem to handle these nicely. I'm not completely sure, but my impression is that they don't get handled as expected because the typed parameter wrangling expects the sub-tree to have identifier and type, whereas there is an extra layer in the tree when the arbitrary args or kwargs either typed (either list_splat_pattern or dictionary_splat_pattern). At the moment, if I generate annotations for the example function given above, the identifier comes out empty i.e. the intended annotation isn't generated.

The tricky thing here is that I'm not sure if this is a neogen bug or a tree-sitter bug. Tree-sitter seems to parse the syntax correctly, but maybe it is missing something. The reason this seems possible is that there is e.g. "default_parameter" and "typed_default_paramter" but there is no equivalent pair for "list_splat_pattern" (i.e. there is no "typed_splat_pattern"). If you think this is actually a tree-sitter bug, which neogen could then handle, I'm happy to open an issue there instead.

Other questions:

  • What is the best way to report this? I see there isn't a test folder so I can't easily make a failing test. Are screenshots/gifs preferred? Or some other format?

(As a side note, I don't think PEP 692 causes any issues for the above, but maybe someone else sees something I don't)

@znicholls
Copy link
Author

znicholls commented Jan 8, 2024

For cross-reference, it seems like the tree sitter folks are happy with the parsing (nvim-treesitter/nvim-treesitter#5874) so I think it probably needs a change in the type handling logic in neogen

@danymat danymat added the bug Something isn't working label Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants