X Tutup
Skip to content

Commit 3cfda64

Browse files
committed
Catch and raise OSError
1 parent 3b83c02 commit 3cfda64

File tree

10 files changed

+15
-15
lines changed

10 files changed

+15
-15
lines changed

bpython/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def flush(self):
168168
def write(self, value):
169169
# XXX IPython expects sys.stdin.write to exist, there will no doubt be
170170
# others, so here's a hack to keep them happy
171-
raise IOError(errno.EBADF, "sys.stdin is read-only")
171+
raise OSError(errno.EBADF, "sys.stdin is read-only")
172172

173173
def isatty(self):
174174
return True

bpython/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def get_key_no_doublebind(command):
268268
)
269269
try:
270270
load_theme(struct, path, struct.color_scheme, default_colors)
271-
except EnvironmentError:
271+
except OSError:
272272
sys.stderr.write(
273273
f"Could not load theme '{color_scheme_name}'.\n"
274274
)

bpython/curtsiesfrontend/repl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def flush(self):
198198
def write(self, value):
199199
# XXX IPython expects sys.stdin.write to exist, there will no doubt be
200200
# others, so here's a hack to keep them happy
201-
raise IOError(errno.EBADF, "sys.stdin is read-only")
201+
raise OSError(errno.EBADF, "sys.stdin is read-only")
202202

203203
def close(self):
204204
# hack to make closing stdin a nop
@@ -666,7 +666,7 @@ def process_control_event(self, e):
666666
elif isinstance(e, bpythonevents.RunStartupFileEvent):
667667
try:
668668
self.startup()
669-
except IOError as e:
669+
except OSError as e:
670670
self.status_bar.message(
671671
_("Executing PYTHONSTARTUP failed: %s") % (e,)
672672
)

bpython/filelock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def acquire(self):
8080
try:
8181
fcntl.flock(self.fileobj, self.mode)
8282
self.locked = True
83-
except IOError as e:
83+
except OSError as e:
8484
if e.errno != errno.ENOLCK:
8585
raise e
8686

bpython/history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def append_reload_and_write(self, s, filename, encoding):
221221
self.save_to(hfile, entries, self.hist_size)
222222

223223
self.entries = entries
224-
except EnvironmentError as err:
224+
except OSError as err:
225225
raise RuntimeError(
226226
_("Error occurred while writing to file %s (%s)")
227227
% (filename, err.strerror)

bpython/importcompletion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def find_modules(path):
136136

137137
try:
138138
filenames = os.listdir(path)
139-
except EnvironmentError:
139+
except OSError:
140140
filenames = []
141141

142142
finder = importlib.machinery.FileFinder(path)
@@ -172,7 +172,7 @@ def find_modules(path):
172172
is_package = True
173173
else:
174174
pathname = spec.origin
175-
except (ImportError, IOError, SyntaxError):
175+
except (ImportError, OSError, SyntaxError):
176176
continue
177177
except UnicodeEncodeError:
178178
# Happens with Python 3 when there is a filename in some

bpython/inspection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def fixlongargs(f, argspec):
164164
keys = argspec[0][-len(values) :]
165165
try:
166166
src = inspect.getsourcelines(f)
167-
except (IOError, IndexError):
167+
except (OSError, IndexError):
168168
# IndexError is raised in inspect.findsource(), can happen in
169169
# some situations. See issue #94.
170170
return

bpython/pager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def page(data, use_internal=False):
5858
# pager command not found, fall back to internal pager
5959
page_internal(data)
6060
return
61-
except IOError as e:
61+
except OSError as e:
6262
if e.errno != errno.EPIPE:
6363
raise
6464
while True:

bpython/repl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def __init__(self, interp, config):
445445
self.rl_history.load(
446446
pythonhist, getpreferredencoding() or "ascii"
447447
)
448-
except EnvironmentError:
448+
except OSError:
449449
pass
450450

451451
self.completers = autocomplete.get_default_completer(
@@ -660,7 +660,7 @@ def get_source_of_current_name(self):
660660
return inspection.get_source_unicode(obj)
661661
except (AttributeError, NameError) as e:
662662
msg = _("Cannot get source: %s") % (e,)
663-
except IOError as e:
663+
except OSError as e:
664664
msg = f"{e}"
665665
except TypeError as e:
666666
if "built-in" in f"{e}":
@@ -857,7 +857,7 @@ def write2file(self):
857857
try:
858858
with open(fn, mode) as f:
859859
f.write(stdout_text)
860-
except IOError as e:
860+
except OSError as e:
861861
self.interact.notify(_("Error writing file '%s': %s") % (fn, e))
862862
else:
863863
self.interact.notify(_("Saved to %s.") % (fn,))
@@ -1166,7 +1166,7 @@ def edit_config(self):
11661166
os.makedirs(containing_dir)
11671167
with open(self.config.config_path, "w") as f:
11681168
f.write(default_config)
1169-
except (IOError, OSError) as e:
1169+
except OSError as e:
11701170
self.interact.notify(
11711171
_("Error writing file '%s': %s")
11721172
% (self.config.config.path, e)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def git_describe_to_python_version(version):
102102
with open(version_file) as vf:
103103
version = vf.read().strip().split("=")[-1].replace("'", "")
104104
version = version.strip()
105-
except IOError:
105+
except OSError:
106106
pass
107107

108108
with open(version_file, "w") as vf:

0 commit comments

Comments
 (0)
X Tutup