Skip to content

Commit 9690eee

Browse files
authored
Merge branch 'main' into thread_name_fix
2 parents 5e5effb + 3f23888 commit 9690eee

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

Lib/test/test_io/test_general.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5029,12 +5029,12 @@ def write(self, b: bytes):
50295029
pass
50305030

50315031
def test_reader_subclass(self):
5032-
self.assertIsSubclass(MyReader, io.Reader[bytes])
5033-
self.assertNotIsSubclass(str, io.Reader[bytes])
5032+
self.assertIsSubclass(self.MyReader, io.Reader)
5033+
self.assertNotIsSubclass(str, io.Reader)
50345034

50355035
def test_writer_subclass(self):
5036-
self.assertIsSubclass(MyWriter, io.Writer[bytes])
5037-
self.assertNotIsSubclass(str, io.Writer[bytes])
5036+
self.assertIsSubclass(self.MyWriter, io.Writer)
5037+
self.assertNotIsSubclass(str, io.Writer)
50385038

50395039

50405040
def load_tests(loader, tests, pattern):
@@ -5048,6 +5048,7 @@ def load_tests(loader, tests, pattern):
50485048
CTextIOWrapperTest, PyTextIOWrapperTest,
50495049
CMiscIOTest, PyMiscIOTest,
50505050
CSignalsTest, PySignalsTest, TestIOCTypes,
5051+
ProtocolsTest,
50515052
)
50525053

50535054
# Put the namespaces of the IO module we are testing and some useful mock

Tools/c-analyzer/c_parser/parser/__init__.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116
* alt impl using a state machine (& tokenizer or split on delimiters)
117117
"""
118118

119+
import textwrap
120+
119121
from ..info import ParsedItem
120122
from ._info import SourceInfo
121123

@@ -208,7 +210,27 @@ def _iter_source(lines, *, maxtext=11_000, maxlines=200, showtext=False):
208210
return
209211
# At this point either the file ended prematurely
210212
# or there's "too much" text.
211-
filename, lno, text = srcinfo.filename, srcinfo._start, srcinfo.text
213+
filename, lno_from, lno_to = srcinfo.filename, srcinfo.start, srcinfo.end
214+
text = srcinfo.text
212215
if len(text) > 500:
213216
text = text[:500] + '...'
214-
raise Exception(f'unmatched text ({filename} starting at line {lno}):\n{text}')
217+
218+
if srcinfo.too_much_text(maxtext):
219+
msg = f'''
220+
too much text, try to increase MAX_SIZES[MAXTEXT] in cpython/_parser.py
221+
{filename} starting at line {lno_from} to {lno_to}
222+
has code with length {len(text)} greater than {maxtext}:
223+
{text}
224+
'''
225+
raise RuntimeError(textwrap.dedent(msg))
226+
227+
if srcinfo.too_many_lines(maxlines):
228+
msg = f'''
229+
too many lines, try to increase MAX_SIZES[MAXLINES] in cpython/_parser.py
230+
{filename} starting at line {lno_from} to {lno_to}
231+
has code with number of lines {lno_to - lno_from} greater than {maxlines}:
232+
{text}
233+
'''
234+
raise RuntimeError(textwrap.dedent(msg))
235+
236+
raise RuntimeError(f'unmatched text ({filename} starting at line {lno_from}):\n{text}')

Tools/c-analyzer/c_parser/parser/_info.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,16 @@ def resolve(self, kind, data, name, parent=None):
123123
def done(self):
124124
self._set_ready()
125125

126+
def too_much_text(self, maxtext):
127+
return maxtext and len(self.text) > maxtext
128+
129+
def too_many_lines(self, maxlines):
130+
return maxlines and self.end - self.start > maxlines
131+
126132
def too_much(self, maxtext, maxlines):
127-
if maxtext and len(self.text) > maxtext:
133+
if self.too_much_text(maxtext):
128134
pass
129-
elif maxlines and self.end - self.start > maxlines:
135+
elif self.too_many_lines(maxlines):
130136
pass
131137
else:
132138
return False

Tools/c-analyzer/cpython/_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def clean_lines(text):
326326
_abs('Modules/_testcapimodule.c'): (20_000, 400),
327327
_abs('Modules/expat/expat.h'): (10_000, 400),
328328
_abs('Objects/stringlib/unicode_format.h'): (10_000, 400),
329-
_abs('Objects/typeobject.c'): (35_000, 200),
329+
_abs('Objects/typeobject.c'): (380_000, 13_000),
330330
_abs('Python/compile.c'): (20_000, 500),
331331
_abs('Python/optimizer.c'): (100_000, 5_000),
332332
_abs('Python/parking_lot.c'): (40_000, 1000),

0 commit comments

Comments
 (0)