Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for function type comments#24

Open
ilevkivskyi wants to merge 9 commits intomainfrom
add-type-comments
Open

Add support for function type comments#24
ilevkivskyi wants to merge 9 commits intomainfrom
add-type-comments

Conversation

@ilevkivskyi
Copy link
Collaborator

Fixes #1

Implementation is relatively straightforward, although I don't handle all edge cases yet. I manually checked this fixes few dozen tests in mypy. Couple notes:

  • It looks like for some reason Ruff lexer doesn't have any public function that exposes full token stream. I only found a function returning token kinds. So for now we are forced to call parse() on the original function type comment just to get the token stream and split comment into argument types and return type.
  • There are some .clone() calls on the parsed comments. I am not a Rust performance expert, but it looks like this is inevitable since we need to mutate them (relocate to meaningful locations, so that they can be used as context for type errors in mypy).

@ilevkivskyi ilevkivskyi requested a review from JukkaL March 2, 2026 18:43
@ilevkivskyi
Copy link
Collaborator Author

I just realized that I allocate an extra vector for each function even if it doesn't use type comments, but an alternative would be ugly (because of per-argument comments support), so I propose to think about optimizing this later.

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.

Support function type comments

1 participant