mirror of
https://github.com/Instagram/LibCST.git
synced 2025-12-23 10:35:53 +00:00
Refactor CodePosition
Renames `CodePosition` to `CodeRange` and stores start and end position as a `CodePosition` dataclass to avoid the ambiguity of using tuples.
This commit is contained in:
parent
d0ecb018e1
commit
39e4e433d8
38 changed files with 180 additions and 160 deletions
|
|
@ -7,7 +7,7 @@
|
|||
from typing import Callable, Optional
|
||||
|
||||
import libcst.nodes as cst
|
||||
from libcst.nodes._internal import CodePosition
|
||||
from libcst.nodes._internal import CodeRange
|
||||
from libcst.nodes.tests.base import CSTNodeTest
|
||||
from libcst.parser import parse_expression
|
||||
from libcst.testing.utils import data_provider
|
||||
|
|
@ -152,7 +152,7 @@ class LambdaCreationTest(CSTNodeTest):
|
|||
cst.Number(cst.Integer("5")),
|
||||
),
|
||||
'lambda first, second, third = 1.0, fourth = 1.5, *, bar = "one", baz, biz = "two": 5',
|
||||
CodePosition((1, 0), (1, 84)),
|
||||
CodeRange.create((1, 0), (1, 84)),
|
||||
),
|
||||
# Test star_arg
|
||||
(
|
||||
|
|
@ -242,12 +242,12 @@ class LambdaCreationTest(CSTNodeTest):
|
|||
rpar=(cst.RightParen(whitespace_before=cst.SimpleWhitespace(" ")),),
|
||||
),
|
||||
"( lambda : 5 )",
|
||||
CodePosition((1, 2), (1, 13)),
|
||||
CodeRange.create((1, 2), (1, 13)),
|
||||
),
|
||||
)
|
||||
)
|
||||
def test_valid(
|
||||
self, node: cst.CSTNode, code: str, position: Optional[CodePosition] = None
|
||||
self, node: cst.CSTNode, code: str, position: Optional[CodeRange] = None
|
||||
) -> None:
|
||||
self.validate_node(node, code, expected_position=position)
|
||||
|
||||
|
|
@ -927,6 +927,6 @@ class LambdaParserTest(CSTNodeTest):
|
|||
)
|
||||
)
|
||||
def test_valid(
|
||||
self, node: cst.CSTNode, code: str, position: Optional[CodePosition] = None
|
||||
self, node: cst.CSTNode, code: str, position: Optional[CodeRange] = None
|
||||
) -> None:
|
||||
self.validate_node(node, code, parse_expression, position)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue