bpo-41058: Use source file encoding in pdb.find_function(). (GH-21010)
(cherry picked from commit 19fcffa92773e008e4f5efb80047420a0cfafeec)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
diff --git a/Lib/pdb.py b/Lib/pdb.py
index bf503f1..931a039 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -79,6 +79,7 @@
import pprint
import signal
import inspect
+import tokenize
import traceback
import linecache
@@ -93,7 +94,7 @@
def find_function(funcname, filename):
cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname))
try:
- fp = open(filename)
+ fp = tokenize.open(filename)
except OSError:
return None
# consumer of this info expects the first line to be 1