Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Lib/test/test_capi/test_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ def test_source(self):
def test_source_discard(self):
_testinternalcapi.test_tokenizer_source_discard()

def test_cursor(self):
_testinternalcapi.test_tokenizer_cursor()


if __name__ == "__main__":
unittest.main()
11 changes: 11 additions & 0 deletions Lib/test/test_codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def test_valid(self, compiler):
av("def f():\n pass\n#foo\n")
av("@a.b.c\ndef f():\n pass\n")

@subTests('symbol', ('single', 'exec'))
@subTests('prefix', ('', 'f', 't'))
def test_incomplete_string_diagnostics(self, symbol, prefix):
opening = f' á = {prefix}"""first\n'
source = 'if True:\n' + opening + 'second'
with self.assertRaises(_IncompleteInputError) as cm:
Compile()(source, '<input>', symbol)
text = opening + 'second' + ('\n' if symbol == 'exec' else '')
self.assertEqual(cm.exception.args, (
'incomplete input', ('<input>', 2, 9, text, 2, -1)))

@subTests('compiler', COMPILERS)
def test_incomplete(self, compiler):
ai = functools.partial(self.assertIncomplete, compiler=compiler)
Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ def read_until(marker, start=0):

@cpython_only
def test_lexer_buffer_realloc_with_null_start(self):
# gh-144759: NULL pointer arithmetic in the lexer when start and
# multi_line_start are NULL (uninitialized in tok_mode_stack[0])
# and the lexer buffer is reallocated while parsing long input.
# gh-144759: NULL pointer arithmetic when the lexer buffer grows
# while parsing long input.
long_value = "a" * 2000
user_input = dedent(f"""\
x = f'{{{long_value!r}}}'
Expand Down
26 changes: 22 additions & 4 deletions Lib/test/test_source_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import unittest
from test import support
from test.support import script_helper
from test.support.os_helper import TESTFN, unlink, rmtree
from test.support.import_helper import unload
from test.support.os_helper import TESTFN, TESTFN_ASCII, unlink, rmtree
from test.support.import_helper import import_module, unload
import importlib
import os
import sys
Expand Down Expand Up @@ -83,12 +83,30 @@ def test_truncated_utf8_at_eof(self):
self.assertRaises(SyntaxError, compile, seq, '<test>', 'exec')

def test_invalid_utf8_offset_after_non_ascii(self):
for name in ('é', 'éé', '𝒜'):
with self.subTest(name=name):
source = ('x = ' + name).encode() + b'\xff\n'
with self.assertRaises(SyntaxError) as caught:
compile(source, '<test>', 'exec')
error = caught.exception
self.assertEqual(
(error.lineno, error.offset, error.end_lineno, error.end_offset),
(1, 5 + len(name), 1, 5 + len(name)),
)

@support.cpython_only
def test_invalid_utf8_file_offset_after_non_ascii(self):
_testcapi = import_module('_testcapi')
self.addCleanup(unlink, TESTFN_ASCII)
with open(TESTFN_ASCII, 'wb') as f:
f.write(b'\nx = \xc3\xa9\xc3\xa9\xff\n')
with self.assertRaises(SyntaxError) as caught:
compile(b"x = \xc3\xa9\xff\n", "<test>", "exec")
_testcapi.run_file(
os.fsencode(TESTFN_ASCII), _testcapi.Py_file_input, {})
error = caught.exception
self.assertEqual(
(error.lineno, error.offset, error.end_lineno, error.end_offset),
(1, 6, 1, 6),
(2, 7, 2, 7),
)

def test_long_bom_conflict_message_is_not_truncated(self):
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_tstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def test_nested_templates(self):

def test_syntax_errors(self):
for case, err in (
('t"""{(\n1\n)}\ntail', "unterminated triple-quoted t-string literal"),
('f"""{(\n1\n)}\ntail', "unterminated triple-quoted f-string literal"),
("t'", "unterminated t-string literal"),
("t'''", "unterminated triple-quoted t-string literal"),
("t''''", "unterminated triple-quoted t-string literal"),
Expand Down
7 changes: 2 additions & 5 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,11 @@ PEGEN_OBJS= \
Parser/peg_api.o

TOKENIZER_OBJS= \
Parser/lexer/buffer.o \
Parser/lexer/lexer.o \
Parser/lexer/layout.o \
Parser/lexer/number.o \
Parser/lexer/state.o \
Parser/lexer/string.o \
Parser/tokenizer/cursor.o \
Parser/tokenizer/decoder.o \
Parser/tokenizer/reader.o \
Parser/tokenizer/source.o \
Expand All @@ -411,11 +410,9 @@ PEGEN_HEADERS= \
$(srcdir)/Parser/string_parser.h

TOKENIZER_HEADERS= \
Parser/lexer/buffer.h \
Parser/lexer/lexer.h \
Parser/lexer/lexer_internal.h \
Parser/lexer/state.h \
Parser/tokenizer/cursor.h \
Parser/tokenizer/reader.h \
Parser/tokenizer/reader_internal.h \
Parser/tokenizer/source.h \
Expand Down Expand Up @@ -3463,7 +3460,7 @@ MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.
MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_openssl_mem.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h
MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h
MODULE__TESTLIMITEDCAPI_DEPS=$(srcdir)/Modules/_testlimitedcapi/testcapi_long.h $(srcdir)/Modules/_testlimitedcapi/parts.h $(srcdir)/Modules/_testlimitedcapi/util.h
MODULE__TESTINTERNALCAPI_DEPS=$(srcdir)/Modules/_testinternalcapi/parts.h $(srcdir)/Parser/tokenizer/cursor.h $(srcdir)/Parser/tokenizer/source.h $(srcdir)/Python/ceval.h $(srcdir)/Modules/_testinternalcapi/test_targets.h $(srcdir)/Modules/_testinternalcapi/test_cases.c.h
MODULE__TESTINTERNALCAPI_DEPS=$(srcdir)/Modules/_testinternalcapi/parts.h $(srcdir)/Parser/tokenizer/source.h $(srcdir)/Python/ceval.h $(srcdir)/Modules/_testinternalcapi/test_targets.h $(srcdir)/Modules/_testinternalcapi/test_cases.c.h
MODULE__SQLITE3_DEPS=$(srcdir)/Modules/_sqlite/connection.h $(srcdir)/Modules/_sqlite/cursor.h $(srcdir)/Modules/_sqlite/microprotocols.h $(srcdir)/Modules/_sqlite/module.h $(srcdir)/Modules/_sqlite/prepare_protocol.h $(srcdir)/Modules/_sqlite/row.h $(srcdir)/Modules/_sqlite/util.h
MODULE__ZSTD_DEPS=$(srcdir)/Modules/_zstd/_zstdmodule.h $(srcdir)/Modules/_zstd/buffer.h $(srcdir)/Modules/_zstd/zstddict.h

Expand Down
Loading
Loading