Skip to content

Commit

Permalink
pythongh-102799: use exception instance instead of exc_info
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Mar 21, 2023
1 parent 7f760c2 commit 720a696
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def currentframe():
"""Return the frame object for the caller's stack frame."""
try:
raise Exception
except Exception:
return sys.exc_info()[2].tb_frame.f_back
except Exception as exc:
return exc.__traceback__.tb_frame.f_back

#
# _srcfile is used when walking the stack to check when we've got the first
Expand Down
2 changes: 1 addition & 1 deletion Lib/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ def _instantiate(self, klass, args):
value = klass(*args)
except TypeError as err:
raise TypeError("in constructor for %s: %s" %
(klass.__name__, str(err)), sys.exc_info()[2])
(klass.__name__, str(err)), err.__traceback__)
else:
value = klass.__new__(klass)
self.append(value)
Expand Down
4 changes: 2 additions & 2 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ def addpackage(sitedir, name, known_paths):
if not dircase in known_paths and os.path.exists(dir):
sys.path.append(dir)
known_paths.add(dircase)
except Exception:
except Exception as exc:
print("Error processing line {:d} of {}:\n".format(n+1, fullname),
file=sys.stderr)
import traceback
for record in traceback.format_exception(*sys.exc_info()):
for record in traceback.format_exception(exc):
for line in record.splitlines():
print(' '+line, file=sys.stderr)
print("\nRemainder of file ignored", file=sys.stderr)
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/inspect_fodder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def abuse(self, a, b, c):
def argue(self, a, b, c):
try:
spam(a, b, c)
except:
self.ex = sys.exc_info()
except BaseException as e:
self.ex = e
self.tr = inspect.trace()

@property
Expand Down Expand Up @@ -78,8 +78,8 @@ async def lobbest(grenade):
currentframe = inspect.currentframe()
try:
raise Exception()
except:
tb = sys.exc_info()[2]
except BaseException as e:
tb = e.__traceback__

class Callable:
def __call__(self, *args):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def __init__(self, *args, **kwargs):
git.abuse(7, 8, 9)

def test_abuse_done(self):
self.istest(inspect.istraceback, 'git.ex[2]')
self.istest(inspect.istraceback, 'git.ex.__traceback__')
self.istest(inspect.isframe, 'mod.fr')

def test_stack(self):
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def __exit__(self, *exc_info):
try:
if mgr.__exit__(*ex):
ex = (None, None, None)
except:
ex = sys.exc_info()
except BaseException as e:
ex = e
self.entered = None
if ex is not exc_info:
raise ex[0](ex[1]).with_traceback(ex[2])
if ex is not exc_info[1]:
raise ex


class MockNested(Nested):
Expand Down
5 changes: 2 additions & 3 deletions Lib/tkinter/filedialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ def test():

# Start off with UTF-8
enc = "utf-8"
import sys

# See whether CODESET is defined
try:
Expand All @@ -477,9 +476,9 @@ def test():
try:
fp=open(openfilename,"r")
fp.close()
except:
except BaseException as exc:
print("Could not open File: ")
print(sys.exc_info()[1])
print(exc)

print("open", openfilename.encode(enc))

Expand Down

0 comments on commit 720a696

Please sign in to comment.