Skip to content

Commit 1d5d891

Browse files
committed
removing NotImplementedError
1 parent 7e777ea commit 1d5d891

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/cs50/cs50.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from distutils.sysconfig import get_python_lib
88
from os.path import abspath, join
99
from termcolor import colored
10-
from traceback import extract_tb, format_exception
10+
from traceback import format_exception
1111

1212

13-
class flushfile():
13+
class _flushfile():
1414
"""
1515
Disable buffering for standard output and standard error.
1616
@@ -28,33 +28,28 @@ def write(self, x):
2828
self.f.flush()
2929

3030

31-
sys.stderr = flushfile(sys.stderr)
32-
sys.stdout = flushfile(sys.stdout)
31+
sys.stderr = _flushfile(sys.stderr)
32+
sys.stdout = _flushfile(sys.stdout)
3333

3434

3535
def eprint(*args, **kwargs):
36-
raise NotImplementedError("The CS50 Library for Python no longer supports eprint, but you can use print instead!")
36+
raise RuntimeError("The CS50 Library for Python no longer supports eprint, but you can use print instead!")
3737

3838

39-
def formatException(type, value, tb):
39+
def _formatException(type, value, tb):
4040
"""
4141
Format traceback, darkening entries from global site-packages directories
4242
and user-specific site-packages directory.
4343
4444
https://stackoverflow.com/a/46071447/5156190
4545
"""
4646

47-
# Don't print tracebacks for deprecations
48-
summary = extract_tb(tb)
49-
if summary and summary[-1].filename == __file__ and type == NotImplementedError:
50-
return "".join(format_exception(type, value, None)).rstrip()
51-
5247
# Absolute paths to site-packages
5348
packages = tuple(join(abspath(p), "") for p in sys.path[1:])
5449

5550
# Highlight lines not referring to files in site-packages
5651
lines = []
57-
for line in format_exception(type, value, tb):
52+
for line in format_exception(type, value, None if type == RuntimeError else tb): # Don't print tracebacks for deprecations
5853
matches = re.search(r"^ File \"([^\"]+)\", line \d+, in .+", line)
5954
if matches and matches.group(1).startswith(packages):
6055
lines += line
@@ -64,11 +59,11 @@ def formatException(type, value, tb):
6459
return "".join(lines).rstrip()
6560

6661

67-
sys.excepthook = lambda type, value, tb: print(formatException(type, value, tb), file=sys.stderr)
62+
sys.excepthook = lambda type, value, tb: print(_formatException(type, value, tb), file=sys.stderr)
6863

6964

7065
def get_char(prompt=None):
71-
raise NotImplementedError("The CS50 Library for Python no longer supports get_char (because Python doesn't have a type for individual characters), but you can use get_string instead!")
66+
raise RuntimeError("The CS50 Library for Python no longer supports get_char, but you can use get_string instead!")
7267

7368

7469
def get_float(prompt):
@@ -100,9 +95,7 @@ def get_int(prompt):
10095
return None
10196
if re.search(r"^[+-]?\d+$", s):
10297
try:
103-
i = int(s, 10)
104-
if type(i) is int: # Could become long in Python 2
105-
return i
98+
return int(s, 10)
10699
except ValueError:
107100
pass
108101

0 commit comments

Comments
 (0)