Skip to content

Commit

Permalink
Do not use SystemError
Browse files Browse the repository at this point in the history
The docs for system error are clear:
```
>>> print(SystemError.__doc__)
Internal error in the Python interpreter.

Please report this to the Python maintainer, along with the traceback,
the Python version, and the hardware/OS platform and version.
```
None of these errors justify contacting a python maintainer.

`OSError` was probably intended, although a few of these make more sense as `ValueError`.
  • Loading branch information
eric-wieser committed Jul 22, 2020
1 parent 1b8a63b commit 7148434
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_executable(path):
with open(path, 'r') as f:
if f.readline()[:2] != "#!":
exn_msg = "File at " + path + " either should not be executable or should have a shebang line"
raise SystemError(exn_msg)
raise OSError(exn_msg)
else:
for file in os.listdir(path):
test_executable(os.path.join(path, file))
Expand Down
10 changes: 5 additions & 5 deletions sympy/printing/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ def preview(expr, output='png', viewer=None, euler=True, packages=(),
try:
candidate_viewers = candidates[output]
except KeyError:
raise SystemError("Invalid output format: %s" % output)
raise ValueError("Invalid output format: %s" % output) from None

for candidate in candidate_viewers:
path = shutil.which(candidate)
if path is not None:
viewer = path
break
else:
raise SystemError(
raise OSError(
"No viewers found for '%s' output format." % output)
else:
if viewer == "StringIO":
Expand All @@ -147,7 +147,7 @@ def preview(expr, output='png', viewer=None, euler=True, packages=(),
raise ValueError("outputbuffer has to be a BytesIO "
"compatible object if viewer=\"BytesIO\"")
elif viewer not in special and not shutil.which(viewer):
raise SystemError("Unrecognized viewer: %s" % viewer)
raise OSError("Unrecognized viewer: %s" % viewer)


if preamble is None:
Expand Down Expand Up @@ -217,7 +217,7 @@ def preview(expr, output='png', viewer=None, euler=True, packages=(),
try:
cmd_variants = commandnames[output]
except KeyError:
raise SystemError("Invalid output format: %s" % output)
raise ValueError("Invalid output format: %s" % output) from None

# find an appropriate command
for cmd_variant in cmd_variants:
Expand Down Expand Up @@ -288,7 +288,7 @@ def preview(expr, output='png', viewer=None, euler=True, packages=(),
from pyglet.image.codecs.png import PNGImageDecoder
img = image.load(join(workdir, src), decoder=PNGImageDecoder())
else:
raise SystemError("pyglet preview works only for 'png' files.")
raise ValueError("pyglet preview works only for 'png' files.")

offset = 25

Expand Down

0 comments on commit 7148434

Please sign in to comment.