X Tutup
Skip to content

Commit 2dd27f9

Browse files
committed
Add type check instead of using exceptions
1 parent 6005b72 commit 2dd27f9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

bpython/patch_linecache.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ def __delitem__(self, key):
5353
return super().__delitem__(key)
5454

5555

56-
def _bpython_clear_linecache():
57-
try:
56+
def _bpython_clear_linecache() -> None:
57+
if isinstance(linecache.cache, BPythonLinecache):
5858
bpython_history = linecache.cache.bpython_history
59-
except AttributeError:
59+
else:
6060
bpython_history = []
6161
linecache.cache = BPythonLinecache()
6262
linecache.cache.bpython_history = bpython_history
@@ -68,12 +68,12 @@ def _bpython_clear_linecache():
6868
linecache.clearcache = _bpython_clear_linecache
6969

7070

71-
def filename_for_console_input(code_string):
71+
def filename_for_console_input(code_string: str) -> str:
7272
"""Remembers a string of source code, and returns
7373
a fake filename to use to retrieve it later."""
74-
try:
74+
if isinstance(linecache.cache, BPythonLinecache):
7575
return linecache.cache.remember_bpython_input(code_string)
76-
except AttributeError:
76+
else:
7777
# If someone else has patched linecache.cache, better for code to
7878
# simply be unavailable to inspect.getsource() than to raise
7979
# an exception.

0 commit comments

Comments
 (0)
X Tutup