Skip to content

Commit 3e8711c

Browse files
committed
Simplify comparisons
1 parent 62833ff commit 3e8711c

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

bpython/line.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def current_word(cursor_offset: int, line: str) -> Optional[LinePart]:
2222
end = pos
2323
word = None
2424
for m in current_word_re.finditer(line):
25-
if m.start(1) < pos and m.end(1) >= pos:
25+
if m.start(1) < pos <= m.end(1):
2626
start = m.start(1)
2727
end = m.end(1)
2828
word = m.group(1)
@@ -37,7 +37,7 @@ def current_word(cursor_offset: int, line: str) -> Optional[LinePart]:
3737
def current_dict_key(cursor_offset: int, line: str) -> Optional[LinePart]:
3838
"""If in dictionary completion, return the current key"""
3939
for m in current_dict_key_re.finditer(line):
40-
if m.start(1) <= cursor_offset and m.end(1) >= cursor_offset:
40+
if m.start(1) <= cursor_offset <= m.end(1):
4141
return LinePart(m.start(1), m.end(1), m.group(1))
4242
return None
4343

@@ -48,7 +48,7 @@ def current_dict_key(cursor_offset: int, line: str) -> Optional[LinePart]:
4848
def current_dict(cursor_offset: int, line: str) -> Optional[LinePart]:
4949
"""If in dictionary completion, return the dict that should be used"""
5050
for m in current_dict_re.finditer(line):
51-
if m.start(2) <= cursor_offset and m.end(2) >= cursor_offset:
51+
if m.start(2) <= cursor_offset <= m.end(2):
5252
return LinePart(m.start(1), m.end(1), m.group(1))
5353
return None
5454

@@ -67,7 +67,7 @@ def current_string(cursor_offset: int, line: str) -> Optional[LinePart]:
6767
string is a string based on previous lines in the buffer."""
6868
for m in current_string_re.finditer(line):
6969
i = 3 if m.group(3) else 4
70-
if m.start(i) <= cursor_offset and m.end(i) >= cursor_offset:
70+
if m.start(i) <= cursor_offset <= m.end(i):
7171
return LinePart(m.start(i), m.end(i), m.group(i))
7272
return None
7373

@@ -108,10 +108,7 @@ def current_object_attribute(
108108
matches = current_object_attribute_re.finditer(word)
109109
next(matches)
110110
for m in matches:
111-
if (
112-
m.start(1) + start <= cursor_offset
113-
and m.end(1) + start >= cursor_offset
114-
):
111+
if m.start(1) + start <= cursor_offset <= m.end(1) + start:
115112
return LinePart(m.start(1) + start, m.end(1) + start, m.group(1))
116113
return None
117114

@@ -131,8 +128,8 @@ def current_from_import_from(
131128
"""
132129
# TODO allow for as's
133130
for m in current_from_import_from_re.finditer(line):
134-
if (m.start(1) < cursor_offset and m.end(1) >= cursor_offset) or (
135-
m.start(2) < cursor_offset and m.end(2) >= cursor_offset
131+
if (m.start(1) < cursor_offset <= m.end(1)) or (
132+
m.start(2) < cursor_offset <= m.end(2)
136133
):
137134
return LinePart(m.start(1), m.end(1), m.group(1))
138135
return None
@@ -162,7 +159,7 @@ def current_from_import_import(
162159
):
163160
start = baseline.end() + m.start(1)
164161
end = baseline.end() + m.end(1)
165-
if start < cursor_offset and end >= cursor_offset:
162+
if start < cursor_offset <= end:
166163
return LinePart(start, end, m.group(1))
167164
return None
168165

@@ -185,7 +182,7 @@ def current_import(cursor_offset: int, line: str) -> Optional[LinePart]:
185182
):
186183
start = baseline.end() + m.start(1)
187184
end = baseline.end() + m.end(1)
188-
if start < cursor_offset and end >= cursor_offset:
185+
if start < cursor_offset <= end:
189186
return LinePart(start, end, m.group(1))
190187
return None
191188

@@ -198,7 +195,7 @@ def current_method_definition_name(
198195
) -> Optional[LinePart]:
199196
"""The name of a method being defined"""
200197
for m in current_method_definition_name_re.finditer(line):
201-
if m.start(1) <= cursor_offset and m.end(1) >= cursor_offset:
198+
if m.start(1) <= cursor_offset <= m.end(1):
202199
return LinePart(m.start(1), m.end(1), m.group(1))
203200
return None
204201

@@ -209,7 +206,7 @@ def current_method_definition_name(
209206
def current_single_word(cursor_offset: int, line: str) -> Optional[LinePart]:
210207
"""the un-dotted word just before or under the cursor"""
211208
for m in current_single_word_re.finditer(line):
212-
if m.start(1) <= cursor_offset and m.end(1) >= cursor_offset:
209+
if m.start(1) <= cursor_offset <= m.end(1):
213210
return LinePart(m.start(1), m.end(1), m.group(1))
214211
return None
215212

@@ -238,6 +235,6 @@ def current_expression_attribute(
238235
"""If after a dot, the attribute being completed"""
239236
# TODO replace with more general current_expression_attribute
240237
for m in current_expression_attribute_re.finditer(line):
241-
if m.start(1) <= cursor_offset and m.end(1) >= cursor_offset:
238+
if m.start(1) <= cursor_offset <= m.end(1):
242239
return LinePart(m.start(1), m.end(1), m.group(1))
243240
return None

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy