-
Notifications
You must be signed in to change notification settings - Fork 38
Description
Feature Description
I propose ignoring type hint nodes in Python code. This includes type hints in variable assignments, function parameters, and function return types. Currently, type hint identifiers (including strings for forward references) are flagged as spelling issues.
Use Case
...
Proposed Solution
When a node is matched for spell checking, ignore it if any of its ancestor nodes in the Tree-sitter AST is a Python type node.
Alternative Solutions
No response
Examples
Editor preview (current behavior):
from typing import Union
# Type nodes in assignment statements.
a: no_typpoa = ...
b: 'no_typpob' = ... # Possible spelling issue 'typpob'. (source=Codebook)
c: "no_typpoc" = ... # Possible spelling issue 'typpoc'. (source=Codebook)
d: """no_typpod""" = ... # Possible spelling issue 'typpod'. (source=Codebook)
e: str | no_typpoe | "no_typpof" # Possible spelling issue 'typpof'. (source=Codebook)
f: Union[str, no_typpog, "no_typpoh"] # Possible spelling issue 'typpoh'. (source=Codebook)
g: list["no_typpoi"] # Possible spelling issue 'typpoi'. (source=Codebook)
# Type nodes in function parameters.
def func(
param_a: no_typpoj, # Possible spelling issue 'typpoj'. (source=Codebook)
param_b: 'no_typpok', # Possible spelling issue 'typpok'. (source=Codebook)
*param_c: no_typpol, # Possible spelling issue 'typpol'. (source=Codebook)
param_d: no_typpom = ...
):
pass
# Type nodes in function return.
def func2() -> str | no_typpon | "no_typpoo": # Possible spelling issue 'typpoo'. (source=Codebook)
pass
After applying the proposed solution, all diagnostics shown above should disappear, since they occur entirely within Python type hint nodes.
Additional Context
There is an existing draft PR (#163) titled “Python: don't check typehints in function signatures”. It seems to focus only on function parameter annotations where the type hint is a direct identifier. Other type hint locations, such as variable annotations and return types, are not covered, and string-based forward references are also left unhandled. This proposal aims to address those gaps by ignoring all Python type hint nodes using the Tree-sitter AST.