Skip to content

Commit ba7c737

Browse files
committed
Revert "Merge pull request RustPython#5731 from arihant2math/pprint-313"
This reverts commit 7d2a7a0, reversing changes made to 494918d.
1 parent c97f4d1 commit ba7c737

11 files changed

Lines changed: 228 additions & 750 deletions

File tree

‎Lib/colorsys.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
__all__ = ["rgb_to_yiq","yiq_to_rgb","rgb_to_hls","hls_to_rgb",
2525
"rgb_to_hsv","hsv_to_rgb"]
2626

27-
# Some floating-point constants
27+
# Some floating point constants
2828

2929
ONE_THIRD = 1.0/3.0
3030
ONE_SIXTH = 1.0/6.0

‎Lib/graphlib.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def done(self, *nodes):
154154
This method unblocks any successor of each node in *nodes* for being returned
155155
in the future by a call to "get_ready".
156156
157-
Raises ValueError if any node in *nodes* has already been marked as
157+
Raises :exec:`ValueError` if any node in *nodes* has already been marked as
158158
processed by a previous call to this method, if a node was not added to the
159159
graph by using "add" or if called without calling "prepare" previously or if
160160
node has not yet been returned by "get_ready".

‎Lib/linecache.py‎

Lines changed: 21 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
that name.
66
"""
77

8+
import functools
9+
import sys
10+
import os
11+
import tokenize
12+
813
__all__ = ["getline", "clearcache", "checkcache", "lazycache"]
914

1015

1116
# The cache. Maps filenames to either a thunk which will provide source code,
1217
# or a tuple (size, mtime, lines, fullname) once loaded.
1318
cache = {}
14-
_interactive_cache = {}
1519

1620

1721
def clearcache():
@@ -45,54 +49,28 @@ def getlines(filename, module_globals=None):
4549
return []
4650

4751

48-
def _getline_from_code(filename, lineno):
49-
lines = _getlines_from_code(filename)
50-
if 1 <= lineno <= len(lines):
51-
return lines[lineno - 1]
52-
return ''
53-
54-
def _make_key(code):
55-
return (code.co_filename, code.co_qualname, code.co_firstlineno)
56-
57-
def _getlines_from_code(code):
58-
code_id = _make_key(code)
59-
if code_id in _interactive_cache:
60-
entry = _interactive_cache[code_id]
61-
if len(entry) != 1:
62-
return _interactive_cache[code_id][2]
63-
return []
64-
65-
6652
def checkcache(filename=None):
6753
"""Discard cache entries that are out of date.
6854
(This is not checked upon each call!)"""
6955

7056
if filename is None:
71-
# get keys atomically
72-
filenames = cache.copy().keys()
73-
else:
57+
filenames = list(cache.keys())
58+
elif filename in cache:
7459
filenames = [filename]
60+
else:
61+
return
7562

7663
for filename in filenames:
77-
try:
78-
entry = cache[filename]
79-
except KeyError:
80-
continue
81-
64+
entry = cache[filename]
8265
if len(entry) == 1:
8366
# lazy cache entry, leave it lazy.
8467
continue
8568
size, mtime, lines, fullname = entry
8669
if mtime is None:
8770
continue # no-op for files loaded via a __loader__
88-
try:
89-
# This import can fail if the interpreter is shutting down
90-
import os
91-
except ImportError:
92-
return
9371
try:
9472
stat = os.stat(fullname)
95-
except (OSError, ValueError):
73+
except OSError:
9674
cache.pop(filename, None)
9775
continue
9876
if size != stat.st_size or mtime != stat.st_mtime:
@@ -104,17 +82,6 @@ def updatecache(filename, module_globals=None):
10482
If something's wrong, print a message, discard the cache entry,
10583
and return an empty list."""
10684

107-
# These imports are not at top level because linecache is in the critical
108-
# path of the interpreter startup and importing os and sys take a lot of time
109-
# and slows down the startup sequence.
110-
try:
111-
import os
112-
import sys
113-
import tokenize
114-
except ImportError:
115-
# These import can fail if the interpreter is shutting down
116-
return []
117-
11885
if filename in cache:
11986
if len(cache[filename]) != 1:
12087
cache.pop(filename, None)
@@ -161,20 +128,16 @@ def updatecache(filename, module_globals=None):
161128
try:
162129
stat = os.stat(fullname)
163130
break
164-
except (OSError, ValueError):
131+
except OSError:
165132
pass
166133
else:
167134
return []
168-
except ValueError: # may be raised by os.stat()
169-
return []
170135
try:
171136
with tokenize.open(fullname) as fp:
172137
lines = fp.readlines()
173138
except (OSError, UnicodeDecodeError, SyntaxError):
174139
return []
175-
if not lines:
176-
lines = ['\n']
177-
elif not lines[-1].endswith('\n'):
140+
if lines and not lines[-1].endswith('\n'):
178141
lines[-1] += '\n'
179142
size, mtime = stat.st_size, stat.st_mtime
180143
cache[filename] = size, mtime, lines, fullname
@@ -203,29 +166,17 @@ def lazycache(filename, module_globals):
203166
return False
204167
# Try for a __loader__, if available
205168
if module_globals and '__name__' in module_globals:
206-
spec = module_globals.get('__spec__')
207-
name = getattr(spec, 'name', None) or module_globals['__name__']
208-
loader = getattr(spec, 'loader', None)
209-
if loader is None:
210-
loader = module_globals.get('__loader__')
169+
name = module_globals['__name__']
170+
if (loader := module_globals.get('__loader__')) is None:
171+
if spec := module_globals.get('__spec__'):
172+
try:
173+
loader = spec.loader
174+
except AttributeError:
175+
pass
211176
get_source = getattr(loader, 'get_source', None)
212177

213178
if name and get_source:
214-
def get_lines(name=name, *args, **kwargs):
215-
return get_source(name, *args, **kwargs)
179+
get_lines = functools.partial(get_source, name)
216180
cache[filename] = (get_lines,)
217181
return True
218182
return False
219-
220-
def _register_code(code, string, name):
221-
entry = (len(string),
222-
None,
223-
[line + '\n' for line in string.splitlines()],
224-
name)
225-
stack = [code]
226-
while stack:
227-
code = stack.pop()
228-
for const in code.co_consts:
229-
if isinstance(const, type(code)):
230-
stack.append(const)
231-
_interactive_cache[_make_key(code)] = entry

‎Lib/pprint.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ def __init__(self, indent=1, width=80, depth=None, stream=None, *,
128128
sort_dicts
129129
If true, dict keys are sorted.
130130
131-
underscore_numbers
132-
If true, digit groups are separated with underscores.
133-
134131
"""
135132
indent = int(indent)
136133
width = int(width)

‎Lib/queue.py‎

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@
1010
except ImportError:
1111
SimpleQueue = None
1212

13-
__all__ = [
14-
'Empty',
15-
'Full',
16-
'ShutDown',
17-
'Queue',
18-
'PriorityQueue',
19-
'LifoQueue',
20-
'SimpleQueue',
21-
]
13+
__all__ = ['Empty', 'Full', 'Queue', 'PriorityQueue', 'LifoQueue', 'SimpleQueue']
2214

2315

2416
try:
@@ -33,10 +25,6 @@ class Full(Exception):
3325
pass
3426

3527

36-
class ShutDown(Exception):
37-
'''Raised when put/get with shut-down queue.'''
38-
39-
4028
class Queue:
4129
'''Create a queue object with a given maximum size.
4230
@@ -66,9 +54,6 @@ def __init__(self, maxsize=0):
6654
self.all_tasks_done = threading.Condition(self.mutex)
6755
self.unfinished_tasks = 0
6856

69-
# Queue shutdown state
70-
self.is_shutdown = False
71-
7257
def task_done(self):
7358
'''Indicate that a formerly enqueued task is complete.
7459
@@ -80,9 +65,6 @@ def task_done(self):
8065
have been processed (meaning that a task_done() call was received
8166
for every item that had been put() into the queue).
8267
83-
shutdown(immediate=True) calls task_done() for each remaining item in
84-
the queue.
85-
8668
Raises a ValueError if called more times than there were items
8769
placed in the queue.
8870
'''
@@ -147,21 +129,15 @@ def put(self, item, block=True, timeout=None):
147129
Otherwise ('block' is false), put an item on the queue if a free slot
148130
is immediately available, else raise the Full exception ('timeout'
149131
is ignored in that case).
150-
151-
Raises ShutDown if the queue has been shut down.
152132
'''
153133
with self.not_full:
154-
if self.is_shutdown:
155-
raise ShutDown
156134
if self.maxsize > 0:
157135
if not block:
158136
if self._qsize() >= self.maxsize:
159137
raise Full
160138
elif timeout is None:
161139
while self._qsize() >= self.maxsize:
162140
self.not_full.wait()
163-
if self.is_shutdown:
164-
raise ShutDown
165141
elif timeout < 0:
166142
raise ValueError("'timeout' must be a non-negative number")
167143
else:
@@ -171,8 +147,6 @@ def put(self, item, block=True, timeout=None):
171147
if remaining <= 0.0:
172148
raise Full
173149
self.not_full.wait(remaining)
174-
if self.is_shutdown:
175-
raise ShutDown
176150
self._put(item)
177151
self.unfinished_tasks += 1
178152
self.not_empty.notify()
@@ -187,21 +161,14 @@ def get(self, block=True, timeout=None):
187161
Otherwise ('block' is false), return an item if one is immediately
188162
available, else raise the Empty exception ('timeout' is ignored
189163
in that case).
190-
191-
Raises ShutDown if the queue has been shut down and is empty,
192-
or if the queue has been shut down immediately.
193164
'''
194165
with self.not_empty:
195-
if self.is_shutdown and not self._qsize():
196-
raise ShutDown
197166
if not block:
198167
if not self._qsize():
199168
raise Empty
200169
elif timeout is None:
201170
while not self._qsize():
202171
self.not_empty.wait()
203-
if self.is_shutdown and not self._qsize():
204-
raise ShutDown
205172
elif timeout < 0:
206173
raise ValueError("'timeout' must be a non-negative number")
207174
else:
@@ -211,8 +178,6 @@ def get(self, block=True, timeout=None):
211178
if remaining <= 0.0:
212179
raise Empty
213180
self.not_empty.wait(remaining)
214-
if self.is_shutdown and not self._qsize():
215-
raise ShutDown
216181
item = self._get()
217182
self.not_full.notify()
218183
return item
@@ -233,29 +198,6 @@ def get_nowait(self):
233198
'''
234199
return self.get(block=False)
235200

236-
def shutdown(self, immediate=False):
237-
'''Shut-down the queue, making queue gets and puts raise ShutDown.
238-
239-
By default, gets will only raise once the queue is empty. Set
240-
'immediate' to True to make gets raise immediately instead.
241-
242-
All blocked callers of put() and get() will be unblocked. If
243-
'immediate', a task is marked as done for each item remaining in
244-
the queue, which may unblock callers of join().
245-
'''
246-
with self.mutex:
247-
self.is_shutdown = True
248-
if immediate:
249-
while self._qsize():
250-
self._get()
251-
if self.unfinished_tasks > 0:
252-
self.unfinished_tasks -= 1
253-
# release all blocked threads in `join()`
254-
self.all_tasks_done.notify_all()
255-
# All getters need to re-check queue-empty to raise ShutDown
256-
self.not_empty.notify_all()
257-
self.not_full.notify_all()
258-
259201
# Override these methods to implement other queue organizations
260202
# (e.g. stack or priority queue).
261203
# These will only be called with appropriate locks held

‎Lib/sched.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
implement simulated time by writing your own functions. This can
1212
also be used to integrate scheduling with STDWIN events; the delay
1313
function is allowed to modify the queue. Time can be expressed as
14-
integers or floating-point numbers, as long as it is consistent.
14+
integers or floating point numbers, as long as it is consistent.
1515
1616
Events are specified by tuples (time, priority, action, argument, kwargs).
1717
As in UNIX, lower priority numbers mean higher priority; in this

‎Lib/test/test_heapq.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import unittest
55
import doctest
66

7+
from test import support
78
from test.support import import_helper
89
from unittest import TestCase, skipUnless
910
from operator import itemgetter

0 commit comments

Comments
 (0)