Skip to content

Commit 3aad465

Browse files
committed
Code review
1 parent 4c4e14c commit 3aad465

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

astroid/rebuilder.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(
9696
manager: AstroidManager,
9797
parser_module: Optional[ParserModule] = None,
9898
data: Optional[str] = None,
99-
):
99+
) -> None:
100100
self._manager = manager
101101
self._data = data.split("\n") if data else None
102102
self._global_names: List[Dict[str, List[nodes.Global]]] = []
@@ -195,8 +195,6 @@ def _get_position_info(
195195
else:
196196
return None
197197

198-
start_token = cast(TokenInfo, start_token) # type: ignore[redundant-cast] # necessary for pyright
199-
200198
# pylint: disable=undefined-loop-variable
201199
return Range(
202200
lineno=node.lineno - 1 + start_token.start[0],

tests/unittest_nodes_position.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ class D: #@
3131
class E: #@
3232
def f():
3333
...
34+
35+
@decorator
36+
class F: #@
37+
...
3438
"""
3539
).strip()
36-
ast_nodes: List[nodes.NodeNG] = builder.extract_node(code) # type: ignore
40+
ast_nodes: List[nodes.NodeNG] = builder.extract_node(code) # type: ignore[assignment]
3741

3842
a = ast_nodes[0]
3943
assert isinstance(a, nodes.ClassDef)
@@ -55,6 +59,10 @@ def f():
5559
assert isinstance(e, nodes.ClassDef)
5660
assert e.position == (13, 0, 13, 7)
5761

62+
f = ast_nodes[5]
63+
assert isinstance(f, nodes.ClassDef)
64+
assert f.position == (18, 0, 18, 7)
65+
5866
@staticmethod
5967
def test_position_function() -> None:
6068
"""Position should only include keyword and name.
@@ -81,7 +89,7 @@ def e(): #@
8189
...
8290
"""
8391
).strip()
84-
ast_nodes: List[nodes.NodeNG] = builder.extract_node(code) # type: ignore
92+
ast_nodes: List[nodes.NodeNG] = builder.extract_node(code) # type: ignore[assignment]
8593

8694
a = ast_nodes[0]
8795
assert isinstance(a, nodes.FunctionDef)
@@ -129,7 +137,7 @@ async def e(): #@
129137
...
130138
"""
131139
).strip()
132-
ast_nodes: List[nodes.NodeNG] = builder.extract_node(code) # type: ignore
140+
ast_nodes: List[nodes.NodeNG] = builder.extract_node(code) # type: ignore[assignment]
133141

134142
a = ast_nodes[0]
135143
assert isinstance(a, nodes.FunctionDef)

0 commit comments

Comments
 (0)