Skip to content

Commit 4940e05

Browse files
Barnabás Domozibarnabasdomozi
authored andcommitted
[PyParser] ASTHelper __equalPos
1 parent f538fa4 commit 4940e05

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

plugins/python/parser/pyparser/asthelper.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ def __getClasses(self) -> List[ast.ClassDef]:
5555
def __getImports(self) -> List[ast.Import | ast.ImportFrom]:
5656
return cast(List[ast.Import | ast.ImportFrom], list(filter(lambda e : isinstance(e, ast.Import) or isinstance(e, ast.ImportFrom), self.astNodes)))
5757

58+
def __equalPos(self, e: ast.expr | ast.stmt, pos: PosInfo):
59+
return (e.lineno == pos.line_start and
60+
e.end_lineno == pos.line_end and
61+
e.col_offset == pos.column_start and
62+
e.end_col_offset == pos.column_end)
63+
5864
def isFunctionCall(self, pos: PosInfo):
5965
for e in self.calls:
6066
func = e.func
6167

6268
if (isinstance(func, ast.Name)):
63-
if (func.lineno == pos.line_start and
64-
func.end_lineno == pos.line_end and
65-
func.col_offset == pos.column_start and
66-
func.end_col_offset == pos.column_end):
69+
if (self.__equalPos(func, pos)):
6770
return True
6871

6972
elif (isinstance(func, ast.Attribute)):
@@ -82,10 +85,7 @@ def isFunctionCall(self, pos: PosInfo):
8285

8386
def isImport(self, pos: PosInfo):
8487
for e in self.imports:
85-
if (e.lineno == pos.line_start and
86-
e.end_lineno == pos.line_end and
87-
e.col_offset == pos.column_start and
88-
e.end_col_offset == pos.column_end):
88+
if (self.__equalPos(e, pos)):
8989
return True
9090

9191
return False
@@ -247,10 +247,7 @@ def getFunctionSignatureByPosition(self, pos: PosInfo) -> str | None:
247247
isinstance(func.end_col_offset, int)):
248248
continue
249249

250-
if not (func.lineno == pos.line_start and
251-
func.end_lineno == pos.line_end and
252-
func.col_offset == pos.column_start and
253-
func.end_col_offset == pos.column_end):
250+
if not (self.__equalPos(func, pos)):
254251
continue
255252

256253
return self.__getFunctionSignature(func)

0 commit comments

Comments
 (0)