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

Appearance settings

Commit 304154c

Browse filesBrowse files
authored
Merge pull request #11066 from anntzer/chainedcomparisons
MNT: Use chained comparisons where reasonable.
2 parents db3be23 + cbd6491 commit 304154c
Copy full SHA for 304154c

File tree

Expand file treeCollapse file tree

8 files changed

+19
-26
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+19
-26
lines changed

‎lib/matplotlib/_constrained_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_constrained_layout.py
+4-10Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,13 @@ def get_axall_tightbbox(ax, renderer):
7777

7878

7979
def in_same_column(colnum0min, colnum0max, colnumCmin, colnumCmax):
80-
if colnum0min >= colnumCmin and colnum0min <= colnumCmax:
81-
return True
82-
if colnum0max >= colnumCmin and colnum0max <= colnumCmax:
83-
return True
84-
return False
80+
return (colnumCmin <= colnum0min <= colnumCmax
81+
or colnumCmin <= colnum0max <= colnumCmax)
8582

8683

8784
def in_same_row(rownum0min, rownum0max, rownumCmin, rownumCmax):
88-
if rownum0min >= rownumCmin and rownum0min <= rownumCmax:
89-
return True
90-
if rownum0max >= rownumCmin and rownum0max <= rownumCmax:
91-
return True
92-
return False
85+
return (rownumCmin <= rownum0min <= rownumCmax
86+
or rownumCmin <= rownum0max <= rownumCmax)
9387

9488

9589
######################################################

‎lib/matplotlib/backends/backend_webagg_core.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_webagg_core.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ def _handle_key(key):
8888
code = int(key[key.index('k') + 1:])
8989
value = chr(code)
9090
# letter keys
91-
if code >= 65 and code <= 90:
91+
if 65 <= code <= 90:
9292
if 'shift+' in key:
9393
key = key.replace('shift+', '')
9494
else:
9595
value = value.lower()
9696
# number keys
97-
elif code >= 48 and code <= 57:
97+
elif 48 <= code <= 57:
9898
if 'shift+' in key:
9999
value = ')!@#$%^&*('[int(value)]
100100
key = key.replace('shift+', '')
101101
# function keys
102-
elif code >= 112 and code <= 123:
102+
elif 112 <= code <= 123:
103103
value = 'f%s' % (code - 111)
104104
# number pad keys
105-
elif code >= 96 and code <= 105:
105+
elif 96 <= code <= 105:
106106
value = '%s' % (code - 96)
107107
# keys with shift alternatives
108108
elif code in _SHIFT_LUT and 'shift+' in key:

‎lib/matplotlib/backends/backend_wx.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_wx.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def set_linewidth(self, w):
489489
w = float(w)
490490
DEBUG_MSG("set_linewidth()", 1, self)
491491
self.select()
492-
if w > 0 and w < 1:
492+
if 0 < w < 1:
493493
w = 1
494494
GraphicsContextBase.set_linewidth(self, w)
495495
lw = int(self.renderer.points_to_pixels(self._linewidth))

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ def draw(self, renderer):
304304
combined_transform = transform
305305
extents = paths[0].get_extents(combined_transform)
306306
width, height = renderer.get_canvas_width_height()
307-
if (extents.width < width and
308-
extents.height < height):
307+
if extents.width < width and extents.height < height:
309308
do_single_path_optimization = True
310309

311310
if self._joinstyle:

‎lib/matplotlib/mathtext.py

Copy file name to clipboardExpand all lines: lib/matplotlib/mathtext.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ def _map_virtual_font(self, fontname, font_class, uniindex):
10001000
else:
10011001
lo = mid + 1
10021002

1003-
if uniindex >= range[0] and uniindex <= range[1]:
1003+
if range[0] <= uniindex <= range[1]:
10041004
uniindex = uniindex - range[0] + range[3]
10051005
fontname = range[2]
10061006
elif not doing_sans_conversion:

‎lib/matplotlib/projections/polar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/projections/polar.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ def start_pan(self, x, y, button):
13441344
if button == 1:
13451345
epsilon = np.pi / 45.0
13461346
t, r = self.transData.inverted().transform_point((x, y))
1347-
if t >= angle - epsilon and t <= angle + epsilon:
1347+
if angle - epsilon <= t <= angle + epsilon:
13481348
mode = 'drag_r_labels'
13491349
elif button == 3:
13501350
mode = 'zoom'

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
501501
if figManager is None:
502502
max_open_warning = rcParams['figure.max_open_warning']
503503

504-
if (max_open_warning >= 1 and len(allnums) >= max_open_warning):
504+
if len(allnums) >= max_open_warning >= 1:
505505
warnings.warn(
506506
"More than %d figures have been opened. Figures "
507507
"created through the pyplot interface "

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,25 +2413,25 @@ def tick_values(self, vmin, vmax):
24132413
# major ticks
24142414
if not self.minor:
24152415
ticklocs = []
2416-
if (decade_min <= -1):
2416+
if decade_min <= -1:
24172417
expo = np.arange(decade_min, min(0, decade_max + 1))
24182418
ticklocs.extend(list(10**expo))
2419-
if (decade_min <= 0) and (decade_max >= 0):
2419+
if decade_min <= 0 <= decade_max:
24202420
ticklocs.append(0.5)
2421-
if (decade_max >= 1):
2421+
if decade_max >= 1:
24222422
expo = -np.arange(max(1, decade_min), decade_max + 1)
24232423
ticklocs.extend(list(1 - 10**expo))
24242424

24252425
# minor ticks
24262426
else:
24272427
ticklocs = []
2428-
if (decade_min <= -2):
2428+
if decade_min <= -2:
24292429
expo = np.arange(decade_min, min(-1, decade_max))
24302430
newticks = np.outer(np.arange(2, 10), 10**expo).ravel()
24312431
ticklocs.extend(list(newticks))
2432-
if (decade_min <= 0) and (decade_max >= 0):
2432+
if decade_min <= 0 <= decade_max:
24332433
ticklocs.extend([0.2, 0.3, 0.4, 0.6, 0.7, 0.8])
2434-
if (decade_max >= 2):
2434+
if decade_max >= 2:
24352435
expo = -np.arange(max(2, decade_min), decade_max + 1)
24362436
newticks = 1 - np.outer(np.arange(2, 10), 10**expo).ravel()
24372437
ticklocs.extend(list(newticks))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.