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 04062b6

Browse filesBrowse files
committed
Cleanup while 1: ... and file iteration.
1 parent 43f2f7c commit 04062b6
Copy full SHA for 04062b6

File tree

Expand file treeCollapse file tree

8 files changed

+69
-104
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+69
-104
lines changed

‎examples/misc/multiprocess.py

Copy file name to clipboardExpand all lines: examples/misc/multiprocess.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def terminate(self):
2828
def poll_draw(self):
2929

3030
def call_back():
31-
while 1:
31+
while True:
3232
if not self.pipe.poll():
3333
break
3434

‎lib/matplotlib/afm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/afm.py
+11-26Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _sanity_check(fh):
9191
# do something else with the file.
9292
pos = fh.tell()
9393
try:
94-
line = fh.readline()
94+
line = next(fh)
9595
finally:
9696
fh.seek(pos, 0)
9797

@@ -148,10 +148,7 @@ def _parse_header(fh):
148148
}
149149

150150
d = {}
151-
while 1:
152-
line = fh.readline()
153-
if not line:
154-
break
151+
for line in fh:
155152
line = line.rstrip()
156153
if line.startswith(b'Comment'):
157154
continue
@@ -191,10 +188,7 @@ def _parse_char_metrics(fh):
191188

192189
ascii_d = {}
193190
name_d = {}
194-
while 1:
195-
line = fh.readline()
196-
if not line:
197-
break
191+
for line in fh:
198192
line = line.rstrip().decode('ascii') # Convert from byte-literal
199193
if line.startswith('EndCharMetrics'):
200194
return ascii_d, name_d
@@ -231,20 +225,17 @@ def _parse_kern_pairs(fh):
231225
232226
"""
233227

234-
line = fh.readline()
228+
line = next(fh)
235229
if not line.startswith(b'StartKernPairs'):
236230
raise RuntimeError('Bad start of kern pairs data: %s' % line)
237231

238232
d = {}
239-
while 1:
240-
line = fh.readline()
241-
if not line:
242-
break
233+
for line in fh:
243234
line = line.rstrip()
244-
if len(line) == 0:
235+
if not line:
245236
continue
246237
if line.startswith(b'EndKernPairs'):
247-
fh.readline() # EndKernData
238+
next(fh) # EndKernData
248239
return d
249240
vals = line.split()
250241
if len(vals) != 4 or vals[0] != b'KPX':
@@ -269,12 +260,9 @@ def _parse_composites(fh):
269260
270261
"""
271262
d = {}
272-
while 1:
273-
line = fh.readline()
274-
if not line:
275-
break
263+
for line in fh:
276264
line = line.rstrip()
277-
if len(line) == 0:
265+
if not line:
278266
continue
279267
if line.startswith(b'EndComposites'):
280268
return d
@@ -306,12 +294,9 @@ def _parse_optional(fh):
306294
}
307295

308296
d = {b'StartKernData': {}, b'StartComposites': {}}
309-
while 1:
310-
line = fh.readline()
311-
if not line:
312-
break
297+
for line in fh:
313298
line = line.rstrip()
314-
if len(line) == 0:
299+
if not line:
315300
continue
316301
key = line.split()[0]
317302

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+7-17Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -396,25 +396,15 @@ def _plot_args(self, tup, kwargs):
396396
return ret
397397

398398
def _grab_next_args(self, *args, **kwargs):
399-
400-
remaining = args
401-
while 1:
402-
403-
if len(remaining) == 0:
404-
return
405-
if len(remaining) <= 3:
406-
for seg in self._plot_args(remaining, kwargs):
407-
yield seg
399+
while True:
400+
if not args:
408401
return
409-
410-
if is_string_like(remaining[2]):
411-
isplit = 3
412-
else:
413-
isplit = 2
414-
415-
for seg in self._plot_args(remaining[:isplit], kwargs):
402+
this, args = args[:2], args[2:]
403+
if args and is_string_like(args[0]):
404+
this += args[0],
405+
args = args[1:]
406+
for seg in self._plot_args(this, kwargs):
416407
yield seg
417-
remaining = remaining[isplit:]
418408

419409

420410
class _AxesBase(martist.Artist):

‎lib/matplotlib/backends/backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_ps.py
+41-48Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,55 +1654,48 @@ def pstoeps(tmpfile, bbox=None, rotated=False):
16541654
bbox_info, rotate = None, None
16551655

16561656
epsfile = tmpfile + '.eps'
1657-
with io.open(epsfile, 'wb') as epsh:
1657+
with io.open(epsfile, 'wb') as epsh, io.open(tmpfile, 'rb') as tmph:
16581658
write = epsh.write
1659-
with io.open(tmpfile, 'rb') as tmph:
1660-
line = tmph.readline()
1661-
# Modify the header:
1662-
while line:
1663-
if line.startswith(b'%!PS'):
1664-
write(b"%!PS-Adobe-3.0 EPSF-3.0\n")
1665-
if bbox:
1666-
write(bbox_info.encode('ascii') + b'\n')
1667-
elif line.startswith(b'%%EndComments'):
1668-
write(line)
1669-
write(b'%%BeginProlog\n')
1670-
write(b'save\n')
1671-
write(b'countdictstack\n')
1672-
write(b'mark\n')
1673-
write(b'newpath\n')
1674-
write(b'/showpage {} def\n')
1675-
write(b'/setpagedevice {pop} def\n')
1676-
write(b'%%EndProlog\n')
1677-
write(b'%%Page 1 1\n')
1678-
if rotate:
1679-
write(rotate.encode('ascii') + b'\n')
1680-
break
1681-
elif bbox and (line.startswith(b'%%Bound') \
1682-
or line.startswith(b'%%HiResBound') \
1683-
or line.startswith(b'%%DocumentMedia') \
1684-
or line.startswith(b'%%Pages')):
1685-
pass
1686-
else:
1687-
write(line)
1688-
line = tmph.readline()
1689-
# Now rewrite the rest of the file, and modify the trailer.
1690-
# This is done in a second loop such that the header of the embedded
1691-
# eps file is not modified.
1692-
line = tmph.readline()
1693-
while line:
1694-
if line.startswith(b'%%EOF'):
1695-
write(b'cleartomark\n')
1696-
write(b'countdictstack\n')
1697-
write(b'exch sub { end } repeat\n')
1698-
write(b'restore\n')
1699-
write(b'showpage\n')
1700-
write(b'%%EOF\n')
1701-
elif line.startswith(b'%%PageBoundingBox'):
1702-
pass
1703-
else:
1704-
write(line)
1705-
line = tmph.readline()
1659+
# Modify the header:
1660+
for line in tmph:
1661+
if line.startswith(b'%!PS'):
1662+
write(b"%!PS-Adobe-3.0 EPSF-3.0\n")
1663+
if bbox:
1664+
write(bbox_info.encode('ascii') + b'\n')
1665+
elif line.startswith(b'%%EndComments'):
1666+
write(line)
1667+
write(b'%%BeginProlog\n'
1668+
b'save\n'
1669+
b'countdictstack\n'
1670+
b'mark\n'
1671+
b'newpath\n'
1672+
b'/showpage {} def\n'
1673+
b'/setpagedevice {pop} def\n'
1674+
b'%%EndProlog\n'
1675+
b'%%Page 1 1\n')
1676+
if rotate:
1677+
write(rotate.encode('ascii') + b'\n')
1678+
break
1679+
elif bbox and line.startswith((b'%%Bound', b'%%HiResBound',
1680+
b'%%DocumentMedia', b'%%Pages')):
1681+
pass
1682+
else:
1683+
write(line)
1684+
# Now rewrite the rest of the file, and modify the trailer.
1685+
# This is done in a second loop such that the header of the embedded
1686+
# eps file is not modified.
1687+
for line in tmph:
1688+
if line.startswith(b'%%EOF'):
1689+
write(b'cleartomark\n'
1690+
b'countdictstack\n'
1691+
b'exch sub { end } repeat\n'
1692+
b'restore\n'
1693+
b'showpage\n'
1694+
b'%%EOF\n')
1695+
elif line.startswith(b'%%PageBoundingBox'):
1696+
pass
1697+
else:
1698+
write(line)
17061699

17071700
os.remove(tmpfile)
17081701
shutil.move(epsfile, tmpfile)

‎lib/matplotlib/backends/tkagg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/tkagg.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ def test(aggimage):
4040
blit(p, aggimage)
4141
c.create_image(aggimage.width,aggimage.height,image=p)
4242
blit(p, aggimage)
43-
while 1: r.update_idletasks()
43+
while True: r.update_idletasks()

‎lib/matplotlib/bezier.py

Copy file name to clipboardExpand all lines: lib/matplotlib/bezier.py
+6-9Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t,
113113
114114
- bezier_point_at_t : a function which returns x, y coordinates at *t*
115115
116-
- inside_closedpath : return True if the point is insed the path
116+
- inside_closedpath : return True if the point is inside the path
117117
118118
"""
119119
# inside_closedpath : function
@@ -124,17 +124,14 @@ def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t,
124124
start_inside = inside_closedpath(start)
125125
end_inside = inside_closedpath(end)
126126

127-
if start_inside == end_inside:
128-
if start != end:
129-
raise NonIntersectingPathException(
130-
"the segment does not seem to intersect with the path"
131-
)
127+
if start_inside == end_inside and start != end:
128+
raise NonIntersectingPathException(
129+
"Both points are on the same side of the closed path")
132130

133-
while 1:
131+
while True:
134132

135133
# return if the distance is smaller than the tolerence
136-
if (start[0] - end[0]) ** 2 + \
137-
(start[1] - end[1]) ** 2 < tolerence ** 2:
134+
if np.hypot(start[0] - end[0], start[1] - end[1]) < tolerence:
138135
return t0, t1
139136

140137
# calculate the middle point

‎lib/matplotlib/dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dates.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ def tick_values(self, vmin, vmax):
11471147
ymax = self.base.ge(vmax.year)
11481148

11491149
ticks = [vmin.replace(year=ymin, **self.replaced)]
1150-
while 1:
1150+
while True:
11511151
dt = ticks[-1]
11521152
if dt.year >= ymax:
11531153
return date2num(ticks)

‎lib/matplotlib/mlab.py

Copy file name to clipboardExpand all lines: lib/matplotlib/mlab.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,7 @@ def get_converters(reader, comments):
28982898
process_skiprows(reader)
28992899

29002900
if needheader:
2901-
while 1:
2901+
while True:
29022902
# skip past any comments and consume one line of column header
29032903
row = next(reader)
29042904
if (len(row) and comments is not None and

0 commit comments

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