-
Notifications
You must be signed in to change notification settings - Fork 220
Open
Description
When using PositionProvider
on an IndentedBlock
I expect to get the code range of the whole indented block.
However, if the indented block starts with a FunctionDef
which has decorators, the indented block's code range also starts after the decorators, where the function definition starts.
I have added the following test to libcst/metadata/tests/test_position_provider.py
under class PositionProviderTest
and it fails.
def test_indented_block_starting_with_decorated_function_def(self) -> None:
"""
Tests that the position provider correctly computes positions in an indented block
starting with a decorated function definition.
"""
test = self
class IndentedBlockVisitor(CSTVisitor):
METADATA_DEPENDENCIES = (PositionProvider,)
def visit_IndentedBlock(self, node: cst.IndentedBlock) -> None:
test.assertEqual(
self.get_metadata(PositionProvider, node),
CodeRange((2, 4), (4, 15)),
)
wrapper = MetadataWrapper(
parse_module("def foo():\n @decorator\n def func(): return 42\n return func")
)
wrapper.visit(IndentedBlockVisitor())
Metadata
Metadata
Assignees
Labels
No labels