Last active
February 11, 2021 22:22
-
-
Save koreno/16efbd1f14323090ffc34fab7f8feeda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replace exception hook | |
import sys | |
from traceback import print_exception | |
sys.excepthook = print_exception | |
# meddle with a code line using linecache | |
import linecache | |
lineno = 423 | |
fname = "/home/ofer/Sources/easypy/easypy/collections.py" | |
linecache.getline(fname, lineno) | |
size, mtime, lines, fullname = linecache.cache[fname] | |
lines[lineno - 1] = "NOTHING TO SEE HERE, PLEASE MOVE ALONG..." | |
# run some code that fails | |
from easypy.collections import ListCollection | |
lc = ListCollection() | |
lc.pop_some(1) | |
# Voila | |
Traceback (most recent call last): | |
File "./traceback_demo.py", line 18, in <module> | |
lc.pop_some(1) | |
File "/home/ofer/Sources/easypy/easypy/collections.py", line 481, in pop_some | |
sample_size = self._choose_sampling_size(minimum, maximum) | |
File "/home/ofer/Sources/easypy/easypy/collections.py", line 423, in _choose_sampling_size | |
NOTHING TO SEE HERE, PLEASE MOVE ALONG... | |
File "/usr/lib/python3.8/random.py", line 248, in randint | |
return self.randrange(a, b+1) | |
File "/usr/lib/python3.8/random.py", line 226, in randrange | |
raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width)) | |
ValueError: empty range for randrange() (1, 1, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment