Skip to content

Commit 0e12017

Browse files
Align the remaining runtime error messages with CPython
Follows the SyntaxError work with the non-syntax `wrong error message` markers. Each message was compared against CPython 3.14.7 directly. - structseq: accept CPython's second `dict` argument, reporting "got duplicate or unexpected field name(s)" when a key duplicates a positional field or names none, and raise "readonly attribute" from the field descriptors as member descriptors do. - posix_spawn: validate `scheduler` in the body so a wrong type says "scheduler must be a tuple or None". - socket.sendto: bind by hand to report "sendto() takes 2 or 3 arguments (N given)" and "socket.sendto() takes no keyword arguments". - bz2: report libbzip2's "Invalid data stream", and make a decompressor unusable after a failure instead of resuming from inconsistent state. - import: resolve `__import__` against the running frame's builtins, so `exec(code, {"__builtins__": {}})` raises ImportError, and pass None rather than () as the from-list of a plain import. - symboltable: name the variable as written, not mangled, in "assignment expression cannot rebind comprehension iteration variable". - _pydatetime: raise the message CPython's C _datetime uses when subtracting a naive and an aware datetime; the pure-Python module is the only implementation here. test_hashlib and test_ast stay marked: both need the callee's name, or non-string keyword keys, to reach argument binding, which is a change to the calling convention rather than to a message. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 18d638b commit 0e12017

20 files changed

Lines changed: 190 additions & 54 deletions

‎Lib/_pydatetime.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,10 @@ def __sub__(self, other):
23252325
if myoff == otoff:
23262326
return base
23272327
if myoff is None or otoff is None:
2328-
raise TypeError("cannot mix naive and timezone-aware time")
2328+
# RUSTPYTHON: _pydatetime is the only implementation here, so use
2329+
# the message CPython's C _datetime raises rather than this one's.
2330+
raise TypeError(
2331+
"can't subtract offset-naive and offset-aware datetimes")
23292332
return base + otoff - myoff
23302333

23312334
def __hash__(self):

‎Lib/test/test_ast/test_ast.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ def test_replace_reject_unknown_instance_fields(self):
14291429
self.assertIs(node.ctx, context)
14301430
self.assertRaises(AttributeError, getattr, node, 'unknown')
14311431

1432-
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
1432+
@unittest.expectedFailure # TODO: RUSTPYTHON; needs non-string keyword keys to reach the callee instead of being rejected by the call itself
14331433
def test_replace_non_str_kwarg(self):
14341434
node = ast.Name(id="x")
14351435
errmsg = "got an unexpected keyword argument <object object"

‎Lib/test/test_builtin.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,6 @@ def test_eval_builtins_mapping(self):
988988
ns = {'__builtins__': types.MappingProxyType({})}
989989
self.assertRaisesRegex(NameError, "name 'superglobal' is not defined",
990990
eval, code, ns)
991-
992-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
993991
def test_exec_builtins_mapping_import(self):
994992
code = compile("import foo.bar", "test", "exec")
995993
ns = {'__builtins__': types.MappingProxyType({})}

‎Lib/test/test_bz2.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,6 @@ def test_failure(self):
10311031
self.assertRaises(Exception, bzd.decompress, self.BAD_DATA * 30)
10321032
# Previously, a second call could crash due to internal inconsistency
10331033
self.assertRaises(Exception, bzd.decompress, self.BAD_DATA * 30)
1034-
1035-
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
10361034
def test_decompress_after_data_error(self):
10371035
data = bytes.fromhex(
10381036
"425a6839314159265359000000000000007fffff000000000000000000000000"

‎Lib/test/test_hashlib.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def test_clinic_signature(self):
275275
self._hashlib.new(digest_name, data=b'')
276276
self._hashlib.new(digest_name, string=b'')
277277

278-
@unittest.expectedFailure # TODO: RUSTPYTHON; duplicate positional/keyword arg error message differs
278+
@unittest.expectedFailure # TODO: RUSTPYTHON; needs the callee name in FuncArgs::bind to report "argument for f() given by name (...) and position (...)"
279279
@unittest.skipIf(get_fips_mode(), "skip in FIPS mode")
280280
def test_clinic_signature_errors(self):
281281
nomsg = b''

‎Lib/test/test_named_expressions.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ def test_named_expression_invalid_dict_comprehension_iterable_expression(self):
365365
with self.assertRaisesRegex(SyntaxError, msg):
366366
exec(f"lambda: {code}", {}) # Function scope
367367

368-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
369368
def test_named_expression_invalid_mangled_class_variables(self):
370369
code = """class Foo:
371370
def bar(self):

‎Lib/test/test_plistlib.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,6 @@ def test_dump_aware_datetime_without_aware_datetime_option(self):
11371137
msg = "can't subtract offset-naive and offset-aware datetimes"
11381138
with self.assertRaisesRegex(TypeError, msg):
11391139
plistlib.dumps(dt, fmt=plistlib.FMT_BINARY, aware_datetime=False)
1140-
1141-
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
11421140
def test_dump_utc_aware_datetime_without_aware_datetime_option(self):
11431141
dt = datetime.datetime(2345, 6, 7, 8, tzinfo=datetime.UTC)
11441142
msg = "can't subtract offset-naive and offset-aware datetimes"

‎Lib/test/test_posix.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,8 +2043,6 @@ def test_scheduler_allow_none(self):
20432043
path, args = self.NOOP_PROGRAM[0], self.NOOP_PROGRAM
20442044
pid = self.spawn_func(path, args, os.environ, scheduler=None)
20452045
support.wait_process(pid, exitcode=0)
2046-
2047-
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
20482046
@support.subTests("scheduler", [object(), 1, [1, 2]])
20492047
def test_scheduler_wrong_type(self, scheduler):
20502048
path, args = self.NOOP_PROGRAM[0], self.NOOP_PROGRAM

‎Lib/test/test_socket.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,6 @@ def testSocketError(self):
983983
raise socket.herror
984984
with self.assertRaises(OSError, msg=msg % 'socket.gaierror'):
985985
raise socket.gaierror
986-
987-
@unittest.expectedFailure # TODO: RUSTPYTHON; error message format differs
988986
def testSendtoErrors(self):
989987
# Testing that sendto doesn't mask failures. See #10169.
990988
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

‎Lib/test/test_structseq.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ def test_constructor(self):
110110

111111
s = "123456789"
112112
self.assertEqual("".join(t(s)), s)
113-
114-
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
115113
def test_constructor_with_duplicate_fields(self):
116114
t = time.struct_time
117115

@@ -141,8 +139,6 @@ def test_constructor_with_duplicate_unnamed_fields(self):
141139
with self.assertRaisesRegex(TypeError,
142140
re.escape("got duplicate or unexpected field name(s)")):
143141
os.stat_result((*range(n_visible_fields), -1.0), {'st_atime': -1.0})
144-
145-
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
146142
def test_constructor_with_unknown_fields(self):
147143
t = time.struct_time
148144

@@ -291,8 +287,6 @@ def test_copy_replace_all_fields_visible(self):
291287
copy.replace(t, error=-1)
292288
with self.assertRaisesRegex(TypeError, 'unexpected field name'):
293289
copy.replace(t, user=1, error=-1)
294-
295-
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
296290
def test_copy_replace_with_invisible_fields(self):
297291
assert time.struct_time.n_unnamed_fields == 0
298292
assert time.struct_time.n_sequence_fields < time.struct_time.n_fields

0 commit comments

Comments
 (0)