robotcode-robot 0.95.0__py3-none-any.whl → 0.95.2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- __version__ = "0.95.0"
1
+ __version__ = "0.95.2"
@@ -1,3 +1,4 @@
1
+ import functools
1
2
  from dataclasses import dataclass, field
2
3
  from enum import Enum
3
4
  from typing import (
@@ -142,19 +143,19 @@ class VariableMatcher:
142
143
 
143
144
  self.base = match.base
144
145
 
145
- self.normalized_name = str(normalize(self.base))
146
+ self.normalized_name = normalize(self.base)
146
147
 
147
148
  def __eq__(self, o: object) -> bool:
148
- if isinstance(o, VariableMatcher):
149
+ if type(o) is VariableMatcher:
149
150
  return o.normalized_name == self.normalized_name
150
151
 
151
- if isinstance(o, str):
152
+ if type(o) is str:
152
153
  match = search_variable(o, "$@&%", ignore_errors=True)
153
154
  base = match.base
154
155
  if base is None:
155
156
  return False
156
157
 
157
- normalized = str(normalize(base))
158
+ normalized = normalize(base)
158
159
  return self.normalized_name == normalized
159
160
 
160
161
  return False
@@ -194,10 +195,9 @@ class VariableDefinition(SourceEntity):
194
195
  value: Any = field(default=None, compare=False)
195
196
  value_is_native: bool = field(default=False, compare=False)
196
197
 
197
- matcher: VariableMatcher = field(init=False, compare=False)
198
-
199
- def __post_init__(self) -> None:
200
- self.matcher = VariableMatcher(self.name)
198
+ @functools.cached_property
199
+ def matcher(self) -> VariableMatcher:
200
+ return VariableMatcher(self.name)
201
201
 
202
202
  @single_call
203
203
  def __hash__(self) -> int:
@@ -573,12 +573,10 @@ class ImportsManager:
573
573
  self._resource_document_changed_timer_interval = 1
574
574
  self._resource_document_changed_documents: Set[TextDocument] = set()
575
575
 
576
- self._resource_libdoc_cache: "weakref.WeakKeyDictionary[ast.AST, Dict[Tuple[str, bool], LibraryDoc]]" = (
576
+ self._resource_libdoc_cache: "weakref.WeakKeyDictionary[ast.AST, Dict[str, LibraryDoc]]" = (
577
577
  weakref.WeakKeyDictionary()
578
578
  )
579
579
 
580
- self._process_pool_executor: Optional[ProcessPoolExecutor] = None
581
-
582
580
  def __del__(self) -> None:
583
581
  try:
584
582
  if self._executor is not None:
@@ -1302,9 +1300,8 @@ class ImportsManager:
1302
1300
  self,
1303
1301
  model: ast.AST,
1304
1302
  source: str,
1305
- append_model_errors: bool = True,
1306
1303
  ) -> LibraryDoc:
1307
- key = (source, append_model_errors)
1304
+ key = source
1308
1305
 
1309
1306
  entry = None
1310
1307
  if model in self._resource_libdoc_cache:
@@ -1313,11 +1310,7 @@ class ImportsManager:
1313
1310
  if entry and key in entry:
1314
1311
  return entry[key]
1315
1312
 
1316
- result = get_model_doc(
1317
- model=model,
1318
- source=source,
1319
- append_model_errors=append_model_errors,
1320
- )
1313
+ result = get_model_doc(model=model, source=source)
1321
1314
  if entry is None:
1322
1315
  entry = {}
1323
1316
  self._resource_libdoc_cache[model] = entry
@@ -39,9 +39,8 @@ DEFAULT_BDD_PREFIXES = {"Given ", "When ", "Then ", "And ", "But "}
39
39
 
40
40
 
41
41
  class KeywordFinder:
42
- def __init__(self, namespace: "Namespace", library_doc: LibraryDoc) -> None:
43
- self.namespace = namespace
44
- self.self_library_doc = library_doc
42
+ def __init__(self, namespace: "Namespace") -> None:
43
+ self._namespace = namespace
45
44
 
46
45
  self.diagnostics: List[DiagnosticsEntry] = []
47
46
  self.result_bdd_prefix: Optional[str] = None
@@ -57,9 +56,9 @@ class KeywordFinder:
57
56
  ],
58
57
  ] = {}
59
58
 
60
- self._all_keywords: Optional[List[LibraryEntry]] = None
61
- self._resource_keywords: Optional[List[ResourceEntry]] = None
62
- self._library_keywords: Optional[List[LibraryEntry]] = None
59
+ @functools.cached_property
60
+ def _library_doc(self) -> LibraryDoc:
61
+ return self._namespace.get_library_doc()
63
62
 
64
63
  def reset_diagnostics(self) -> None:
65
64
  self.diagnostics = []
@@ -162,7 +161,7 @@ class KeywordFinder:
162
161
  def _get_keyword_from_self(self, name: str) -> Optional[KeywordDoc]:
163
162
  if get_robot_version() >= (6, 0):
164
163
  found: List[Tuple[Optional[LibraryEntry], KeywordDoc]] = [
165
- (None, v) for v in self.self_library_doc.keywords.iter_all(name)
164
+ (None, v) for v in self._library_doc.keywords.iter_all(name)
166
165
  ]
167
166
  if len(found) > 1:
168
167
  found = self._select_best_matches(found)
@@ -183,7 +182,7 @@ class KeywordFinder:
183
182
  return None
184
183
 
185
184
  try:
186
- return self.self_library_doc.keywords.get(name, None)
185
+ return self._library_doc.keywords.get(name, None)
187
186
  except KeywordError as e:
188
187
  self.diagnostics.append(DiagnosticsEntry(str(e), DiagnosticSeverity.ERROR, Error.KEYWORD_ERROR))
189
188
  raise CancelSearchError from e
@@ -213,15 +212,16 @@ class KeywordFinder:
213
212
 
214
213
  return found[0][1] if found else None
215
214
 
216
- def find_keywords(self, owner_name: str, name: str) -> List[Tuple[LibraryEntry, KeywordDoc]]:
217
- if self._all_keywords is None:
218
- self._all_keywords = list(
219
- chain(
220
- self.namespace._libraries.values(),
221
- self.namespace._resources.values(),
222
- )
215
+ @functools.cached_property
216
+ def _all_keywords(self) -> List[LibraryEntry]:
217
+ return list(
218
+ chain(
219
+ self._namespace._libraries.values(),
220
+ self._namespace._resources.values(),
223
221
  )
222
+ )
224
223
 
224
+ def find_keywords(self, owner_name: str, name: str) -> List[Tuple[LibraryEntry, KeywordDoc]]:
225
225
  if get_robot_version() >= (6, 0):
226
226
  result: List[Tuple[LibraryEntry, KeywordDoc]] = []
227
227
  for v in self._all_keywords:
@@ -271,11 +271,11 @@ class KeywordFinder:
271
271
  def _prioritize_same_file_or_public(
272
272
  self, entries: List[Tuple[Optional[LibraryEntry], KeywordDoc]]
273
273
  ) -> List[Tuple[Optional[LibraryEntry], KeywordDoc]]:
274
- matches = [h for h in entries if h[1].source == self.namespace.source]
274
+ matches = [h for h in entries if h[1].source == self._namespace.source]
275
275
  if matches:
276
276
  return matches
277
277
 
278
- matches = [handler for handler in entries if not handler[1].is_private()]
278
+ matches = [handler for handler in entries if not handler[1].is_private]
279
279
 
280
280
  return matches or entries
281
281
 
@@ -312,23 +312,24 @@ class KeywordFinder:
312
312
  other: Tuple[Optional[LibraryEntry], KeywordDoc],
313
313
  ) -> bool:
314
314
  return (
315
- other[1].matcher.embedded_arguments.match(candidate[1].name) is not None
315
+ other[1].matcher.embedded_arguments is not None
316
+ and candidate[1].matcher.embedded_arguments is not None
317
+ and other[1].matcher.embedded_arguments.match(candidate[1].name) is not None
316
318
  and candidate[1].matcher.embedded_arguments.match(other[1].name) is None
317
319
  )
318
320
 
319
- def _get_keyword_from_resource_files(self, name: str) -> Optional[KeywordDoc]:
320
- if self._resource_keywords is None:
321
- self._resource_keywords = list(chain(self.namespace._resources.values()))
321
+ @functools.cached_property
322
+ def _resource_imports(self) -> List[ResourceEntry]:
323
+ return list(chain(self._namespace._resources.values()))
322
324
 
325
+ def _get_keyword_from_resource_files(self, name: str) -> Optional[KeywordDoc]:
323
326
  if get_robot_version() >= (6, 0):
324
- found: List[Tuple[Optional[LibraryEntry], KeywordDoc]] = []
325
- for v in self._resource_keywords:
326
- r = v.library_doc.keywords.get_all(name)
327
- if r:
328
- found.extend([(v, k) for k in r])
327
+ found: List[Tuple[Optional[LibraryEntry], KeywordDoc]] = [
328
+ (v, k) for v in self._resource_imports for k in v.library_doc.keywords.iter_all(name)
329
+ ]
329
330
  else:
330
331
  found = []
331
- for k in self._resource_keywords:
332
+ for k in self._resource_imports:
332
333
  s = k.library_doc.keywords.get(name, None)
333
334
  if s is not None:
334
335
  found.append((k, s))
@@ -365,27 +366,27 @@ class KeywordFinder:
365
366
  def _get_keyword_based_on_search_order(
366
367
  self, entries: List[Tuple[Optional[LibraryEntry], KeywordDoc]]
367
368
  ) -> List[Tuple[Optional[LibraryEntry], KeywordDoc]]:
368
- for libname in self.namespace.search_order:
369
+ for libname in self._namespace.search_order:
369
370
  for e in entries:
370
371
  if e[0] is not None and eq_namespace(libname, e[0].alias or e[0].name):
371
372
  return [e]
372
373
 
373
374
  return entries
374
375
 
375
- def _get_keyword_from_libraries(self, name: str) -> Optional[KeywordDoc]:
376
- if self._library_keywords is None:
377
- self._library_keywords = list(chain(self.namespace._libraries.values()))
376
+ @functools.cached_property
377
+ def _library_imports(self) -> List[LibraryEntry]:
378
+ return list(chain(self._namespace._libraries.values()))
378
379
 
380
+ def _get_keyword_from_libraries(self, name: str) -> Optional[KeywordDoc]:
379
381
  if get_robot_version() >= (6, 0):
380
- found: List[Tuple[Optional[LibraryEntry], KeywordDoc]] = []
381
- for v in self._library_keywords:
382
- r = v.library_doc.keywords.get_all(name)
383
- if r:
384
- found.extend([(v, k) for k in r])
382
+ found: List[Tuple[Optional[LibraryEntry], KeywordDoc]] = [
383
+ (v, k) for v in self._library_imports for k in v.library_doc.keywords.iter_all(name)
384
+ ]
385
+
385
386
  else:
386
387
  found = []
387
388
 
388
- for k in self._library_keywords:
389
+ for k in self._library_imports:
389
390
  s = k.library_doc.keywords.get(name, None)
390
391
  if s is not None:
391
392
  found.append((k, s))
@@ -463,8 +464,8 @@ class KeywordFinder:
463
464
  def bdd_prefix_regexp(self) -> "re.Pattern[str]":
464
465
  prefixes = (
465
466
  "|".join(
466
- self.namespace.languages.bdd_prefixes
467
- if self.namespace.languages is not None
467
+ self._namespace.languages.bdd_prefixes
468
+ if self._namespace.languages is not None
468
469
  else ["given", "when", "then", "and", "but"]
469
470
  )
470
471
  .replace(" ", r"\s")