Skip to content

Commit 22ebf12

Browse files
committed
Clean up
1 parent 66e999c commit 22ebf12

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

bpython/line.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@
1111
from .lazyre import LazyReCompile
1212

1313
LinePart = namedtuple("LinePart", ["start", "stop", "word"])
14-
1514
current_word_re = LazyReCompile(r"(?<![)\]\w_.])" r"([\w_][\w0-9._]*[(]?)")
1615

1716

1817
def current_word(cursor_offset: int, line: str) -> Optional[LinePart]:
1918
"""the object.attribute.attribute just before or under the cursor"""
20-
pos = cursor_offset
21-
start = pos
22-
end = pos
19+
start = cursor_offset
20+
end = cursor_offset
2321
word = None
2422
for m in current_word_re.finditer(line):
25-
if m.start(1) < pos <= m.end(1):
23+
if m.start(1) < cursor_offset <= m.end(1):
2624
start = m.start(1)
2725
end = m.end(1)
2826
word = m.group(1)
@@ -82,12 +80,11 @@ def current_object(cursor_offset: int, line: str) -> Optional[LinePart]:
8280
if match is None:
8381
return None
8482
start, end, word = match
85-
s = ""
86-
for m in current_object_re.finditer(word):
87-
if m.end(1) + start < cursor_offset:
88-
if s:
89-
s += "."
90-
s += m.group(1)
83+
s = ".".join(
84+
m.group(1)
85+
for m in current_object_re.finditer(word)
86+
if m.end(1) + start < cursor_offset
87+
)
9188
if not s:
9289
return None
9390
return LinePart(start, start + len(s), s)

0 commit comments

Comments
 (0)