aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/doctest.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2023-12-13 02:43:57 +0300
committershadchin <shadchin@yandex-team.com>2023-12-13 03:08:48 +0300
commit5b48aabc614c6d407f885f3b228dc484ad4c5ba9 (patch)
tree602eb5cc5d85bf730c1de1fa50a13c2ee552830d /contrib/tools/python3/src/Lib/doctest.py
parent35d7049b38602e8cbfcd3f96257329a1abce947e (diff)
downloadydb-5b48aabc614c6d407f885f3b228dc484ad4c5ba9.tar.gz
Update Python 3 to 3.11.7
Diffstat (limited to 'contrib/tools/python3/src/Lib/doctest.py')
-rw-r--r--contrib/tools/python3/src/Lib/doctest.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/contrib/tools/python3/src/Lib/doctest.py b/contrib/tools/python3/src/Lib/doctest.py
index a4b85378d1..2a855929ae 100644
--- a/contrib/tools/python3/src/Lib/doctest.py
+++ b/contrib/tools/python3/src/Lib/doctest.py
@@ -569,9 +569,11 @@ class DocTest:
def __lt__(self, other):
if not isinstance(other, DocTest):
return NotImplemented
- return ((self.name, self.filename, self.lineno, id(self))
+ self_lno = self.lineno if self.lineno is not None else -1
+ other_lno = other.lineno if other.lineno is not None else -1
+ return ((self.name, self.filename, self_lno, id(self))
<
- (other.name, other.filename, other.lineno, id(other)))
+ (other.name, other.filename, other_lno, id(other)))
######################################################################
## 3. DocTestParser
@@ -1373,7 +1375,24 @@ class DocTestRunner:
# The example raised an exception: check if it was expected.
else:
- exc_msg = traceback.format_exception_only(*exception[:2])[-1]
+ formatted_ex = traceback.format_exception_only(*exception[:2])
+ if issubclass(exception[0], SyntaxError):
+ # SyntaxError / IndentationError is special:
+ # we don't care about the carets / suggestions / etc
+ # We only care about the error message and notes.
+ # They start with `SyntaxError:` (or any other class name)
+ exception_line_prefixes = (
+ f"{exception[0].__qualname__}:",
+ f"{exception[0].__module__}.{exception[0].__qualname__}:",
+ )
+ exc_msg_index = next(
+ index
+ for index, line in enumerate(formatted_ex)
+ if line.startswith(exception_line_prefixes)
+ )
+ formatted_ex = formatted_ex[exc_msg_index:]
+
+ exc_msg = "".join(formatted_ex)
if not quiet:
got += _exception_traceback(exception)