Skip to content

Commit beb1994

Browse files
committed
Avoid allocation of a list
The list is later turned into a set.
1 parent cd20fd7 commit beb1994

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

bpython/autocomplete.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,27 @@ def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
418418
def format(self, word: str) -> str:
419419
return _after_last_dot(word)
420420

421-
def attr_matches(self, text: str, namespace: Dict[str, Any]) -> List:
421+
def attr_matches(
422+
self, text: str, namespace: Dict[str, Any]
423+
) -> Iterator[str]:
422424
"""Taken from rlcompleter.py and bent to my will."""
423425

424426
m = self.attr_matches_re.match(text)
425427
if not m:
426-
return []
428+
return (_ for _ in ())
427429

428430
expr, attr = m.group(1, 3)
429431
if expr.isdigit():
430432
# Special case: float literal, using attrs here will result in
431433
# a SyntaxError
432-
return []
434+
return (_ for _ in ())
433435
try:
434436
obj = safe_eval(expr, namespace)
435437
except EvaluationError:
436-
return []
438+
return (_ for _ in ())
437439
return self.attr_lookup(obj, expr, attr)
438440

439-
def attr_lookup(self, obj: Any, expr: str, attr: str) -> List:
441+
def attr_lookup(self, obj: Any, expr: str, attr: str) -> Iterator[str]:
440442
"""Second half of attr_matches."""
441443
words = self.list_attributes(obj)
442444
if inspection.hasattr_safe(obj, "__class__"):
@@ -449,12 +451,12 @@ def attr_lookup(self, obj: Any, expr: str, attr: str) -> List:
449451
except ValueError:
450452
pass
451453

452-
matches = []
453454
n = len(attr)
454-
for word in words:
455-
if self.method_match(word, n, attr) and word != "__builtins__":
456-
matches.append(f"{expr}.{word}")
457-
return matches
455+
return (
456+
f"{expr}.{word}"
457+
for word in words
458+
if self.method_match(word, n, attr) and word != "__builtins__"
459+
)
458460

459461
def list_attributes(self, obj: Any) -> List[str]:
460462
# TODO: re-implement dir without AttrCleaner here

0 commit comments

Comments
 (0)