Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbeb1994

Browse files
committed
Avoid allocation of a list
The list is later turned into a set.
1 parentcd20fd7 commitbeb1994

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
defformat(self,word:str)->str:
419419
return_after_last_dot(word)
420420

421-
defattr_matches(self,text:str,namespace:Dict[str,Any])->List:
421+
defattr_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
ifnotm:
426-
return[]
428+
return(_for_in ())
427429

428430
expr,attr=m.group(1,3)
429431
ifexpr.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
exceptEvaluationError:
436-
return[]
438+
return(_for_in ())
437439
returnself.attr_lookup(obj,expr,attr)
438440

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

452-
matches= []
453454
n=len(attr)
454-
forwordinwords:
455-
ifself.method_match(word,n,attr)andword!="__builtins__":
456-
matches.append(f"{expr}.{word}")
457-
returnmatches
455+
return (
456+
f"{expr}.{word}"
457+
forwordinwords
458+
ifself.method_match(word,n,attr)andword!="__builtins__"
459+
)
458460

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp