Skip to content

Commit 04e12a7

Browse files
committed
fix(robot): use casefold for normalizing and remove some local imports in VariableMatcher
1 parent 5a846ab commit 04e12a7

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

packages/robot/src/robotcode/robot/diagnostics/entities.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
)
1313

1414
from robot.parsing.lexer.tokens import Token
15+
from robot.variables.search import search_variable
1516
from robotcode.core.lsp.types import Position, Range
17+
from robotcode.robot.utils.match import normalize
1618

1719
from ..utils.ast import range_from_token
1820

@@ -131,9 +133,6 @@ class InvalidVariableError(Exception):
131133

132134
class VariableMatcher:
133135
def __init__(self, name: str) -> None:
134-
from robot.variables.search import search_variable
135-
from robotcode.robot.utils.match import normalize
136-
137136
self.name = name
138137

139138
match = search_variable(name, "$@&%", ignore_errors=True)
@@ -146,9 +145,6 @@ def __init__(self, name: str) -> None:
146145
self.normalized_name = str(normalize(self.base))
147146

148147
def __eq__(self, o: object) -> bool:
149-
from robot.utils.normalizing import normalize
150-
from robot.variables.search import search_variable
151-
152148
if isinstance(o, VariableMatcher):
153149
return o.normalized_name == self.normalized_name
154150

packages/robot/src/robotcode/robot/diagnostics/library_doc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
from robotcode.robot.utils.stubs import HasError, HasErrors
8787

8888
if get_robot_version() < (7, 0):
89-
from robot.running.handlers import _PythonHandler, _PythonInitHandler
90-
from robot.running.model import ResourceFile
91-
from robot.running.usererrorhandler import UserErrorHandler
92-
from robot.running.userkeyword import UserLibrary
89+
from robot.running.handlers import _PythonHandler, _PythonInitHandler # pyright: ignore[reportMissingImports]
90+
from robot.running.model import ResourceFile # pyright: ignore[reportMissingImports]
91+
from robot.running.usererrorhandler import UserErrorHandler # pyright: ignore[reportMissingImports]
92+
from robot.running.userkeyword import UserLibrary # pyright: ignore[reportMissingImports]
9393

9494
robot_notset = ArgInfo.NOTSET
9595

packages/robot/src/robotcode/robot/utils/match.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from functools import lru_cache
22

3+
_transform_table = str.maketrans("", "", "_ ")
4+
35

46
@lru_cache(maxsize=5000)
57
def normalize(text: str) -> str:
6-
return text.lower().replace("_", "").replace(" ", "")
8+
# return text.lower().replace("_", "").replace(" ", "")
9+
return text.casefold().translate(_transform_table)
710

811

912
@lru_cache(maxsize=5000)

0 commit comments

Comments
 (0)