https://github.com/python/cpython/commit/33f89106d770ab4916e7476aab3e5bf61127eca8
commit: 33f89106d770ab4916e7476aab3e5bf61127eca8
branch: main
author: Sergey Miryanov <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2025-09-02T13:34:22Z
summary:

gh-133158: Adjust c-analyzer `max_sizes` for `typeobject.c` (GH-133159)

This also improves the error message for when a file is too large.

files:
M Tools/c-analyzer/c_parser/parser/__init__.py
M Tools/c-analyzer/c_parser/parser/_info.py
M Tools/c-analyzer/cpython/_parser.py

diff --git a/Tools/c-analyzer/c_parser/parser/__init__.py 
b/Tools/c-analyzer/c_parser/parser/__init__.py
index ff4f303c4a2bec..f3f09107aefce6 100644
--- a/Tools/c-analyzer/c_parser/parser/__init__.py
+++ b/Tools/c-analyzer/c_parser/parser/__init__.py
@@ -116,6 +116,8 @@
 * alt impl using a state machine (& tokenizer or split on delimiters)
 """
 
+import textwrap
+
 from ..info import ParsedItem
 from ._info import SourceInfo
 
@@ -208,7 +210,27 @@ def _iter_source(lines, *, maxtext=11_000, maxlines=200, 
showtext=False):
             return
     # At this point either the file ended prematurely
     # or there's "too much" text.
-    filename, lno, text = srcinfo.filename, srcinfo._start, srcinfo.text
+    filename, lno_from, lno_to = srcinfo.filename, srcinfo.start, srcinfo.end
+    text = srcinfo.text
     if len(text) > 500:
         text = text[:500] + '...'
-    raise Exception(f'unmatched text ({filename} starting at line 
{lno}):\n{text}')
+
+    if srcinfo.too_much_text(maxtext):
+        msg = f'''
+            too much text, try to increase MAX_SIZES[MAXTEXT] in 
cpython/_parser.py
+            {filename} starting at line {lno_from} to {lno_to}
+            has code with length {len(text)} greater than {maxtext}:
+            {text}
+        '''
+        raise RuntimeError(textwrap.dedent(msg))
+
+    if srcinfo.too_many_lines(maxlines):
+        msg = f'''
+            too many lines, try to increase MAX_SIZES[MAXLINES] in 
cpython/_parser.py
+            {filename} starting at line {lno_from} to {lno_to}
+            has code with number of lines {lno_to - lno_from} greater than 
{maxlines}:
+            {text}
+        '''
+        raise RuntimeError(textwrap.dedent(msg))
+
+    raise RuntimeError(f'unmatched text ({filename} starting at line 
{lno_from}):\n{text}')
diff --git a/Tools/c-analyzer/c_parser/parser/_info.py 
b/Tools/c-analyzer/c_parser/parser/_info.py
index 340223db933c90..13b192e2ce982f 100644
--- a/Tools/c-analyzer/c_parser/parser/_info.py
+++ b/Tools/c-analyzer/c_parser/parser/_info.py
@@ -123,10 +123,16 @@ def resolve(self, kind, data, name, parent=None):
     def done(self):
         self._set_ready()
 
+    def too_much_text(self, maxtext):
+        return maxtext and len(self.text) > maxtext
+
+    def too_many_lines(self, maxlines):
+        return maxlines and self.end - self.start > maxlines
+
     def too_much(self, maxtext, maxlines):
-        if maxtext and len(self.text) > maxtext:
+        if self.too_much_text(maxtext):
             pass
-        elif maxlines and self.end - self.start > maxlines:
+        elif self.too_many_lines(maxlines):
             pass
         else:
             return False
diff --git a/Tools/c-analyzer/cpython/_parser.py 
b/Tools/c-analyzer/cpython/_parser.py
index 1e754040eaf1cc..95a474a49229a1 100644
--- a/Tools/c-analyzer/cpython/_parser.py
+++ b/Tools/c-analyzer/cpython/_parser.py
@@ -326,7 +326,7 @@ def clean_lines(text):
     _abs('Modules/_testcapimodule.c'): (20_000, 400),
     _abs('Modules/expat/expat.h'): (10_000, 400),
     _abs('Objects/stringlib/unicode_format.h'): (10_000, 400),
-    _abs('Objects/typeobject.c'): (35_000, 200),
+    _abs('Objects/typeobject.c'): (380_000, 13_000),
     _abs('Python/compile.c'): (20_000, 500),
     _abs('Python/optimizer.c'): (100_000, 5_000),
     _abs('Python/parking_lot.c'): (40_000, 1000),

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to