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:
Ray Zeng 2019-07-03 16:50:46 -07:00 committed by Benjamin Woodruff
parent d0ecb018e1
commit 39e4e433d8
38 changed files with 180 additions and 160 deletions

View file

@ -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)