Instagram / Instagram/LibCST

`CodeRange` provided by `PositionProvider` doesn't include decorators

Open
#972 2 comments 0 reactions 0 assignees View on GitHub
bug codemod
Dominant language
Python
Stars
1.9k
Forks
229
PR merge metrics
No merged PRs in 30d

Description

Hi,

since decorators are sub nodes of `FunctionDef` and `ClassDef` I expected the code range to cover them. Is this intended?

```python
import libcst
import libcst.metadata as l_metadata

metadata_wrapper = libcst.MetadataWrapper(libcst.parse_module("""
@decorator
def function():
pass

@decorator
class Class:
pass
"""))

positions = metadata_wrapper.resolve(l_metadata.PositionProvider)

function_node, class_node = metadata_wrapper.module.body
print("function :", positions[function_node])
print("decorator:", positions[function_node.decorators[0]])
print()
print("class :", positions[class_node])
print("decorator:", positions[class_node.decorators[0]])

# function : CodeRange(start=CodePosition(line=3, column=0), end=CodePosition(line=4, column=8))
# decorator: CodeRange(start=CodePosition(line=2, column=0), end=CodePosition(line=2, column=10))
#
# class : CodeRange(start=CodePosition(line=7, column=0), end=CodePosition(line=8, column=8))
# decorator: CodeRange(start=CodePosition(line=6, column=0), end=CodePosition(line=6, column=10))
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.