Skip to content

Commit aff89c2

Browse files
committed
mark ast & test_genericalias
1 parent 817e4df commit aff89c2

File tree

8 files changed

+53
-58
lines changed

8 files changed

+53
-58
lines changed

Lib/test/test_ast/test_ast.py

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_AST_objects(self):
9797
# "ast.AST constructor takes 0 positional arguments"
9898
ast.AST(2)
9999

100-
@unittest.expectedFailure # TODO: RUSTPYTHON
100+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: "type object 'ast.AST' has no attribute '_fields'" does not match "'AST' object has no attribute '_fields'"
101101
def test_AST_fields_NULL_check(self):
102102
# See: https://github.com/python/cpython/issues/126105
103103
old_value = ast.AST._fields
@@ -115,7 +115,7 @@ def cleanup():
115115
with self.assertRaisesRegex(AttributeError, msg):
116116
ast.AST()
117117

118-
@unittest.expectedFailure # TODO: RUSTPYTHON
118+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: <test.test_ast.test_ast.AST_Tests.test_AST_garbage_collection.<locals>.X object at 0x7e85c3a80> is not None
119119
def test_AST_garbage_collection(self):
120120
class X:
121121
pass
@@ -140,7 +140,7 @@ def test_snippets(self):
140140
with self.subTest(action="compiling", input=i, kind=kind):
141141
compile(ast_tree, "?", kind)
142142

143-
@unittest.expectedFailure # TODO: RUSTPYTHON
143+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: expected some sort of expr, but got <_ast.TemplateStr object at 0x7e85c34e0>
144144
def test_ast_validation(self):
145145
# compile() is the only function that calls PyAST_Validate
146146
snippets_to_validate = exec_tests + single_tests + eval_tests
@@ -439,7 +439,7 @@ def _construct_ast_class(self, cls):
439439
kwargs[name] = self._construct_ast_class(typ)
440440
return cls(**kwargs)
441441

442-
@unittest.expectedFailure # TODO: RUSTPYTHON
442+
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: type object 'arguments' has no attribute '__annotations__'
443443
def test_arguments(self):
444444
x = ast.arguments()
445445
self.assertEqual(x._fields, ('posonlyargs', 'args', 'vararg', 'kwonlyargs',
@@ -590,15 +590,15 @@ def test_no_fields(self):
590590
x = ast.Sub()
591591
self.assertEqual(x._fields, ())
592592

593-
@unittest.expectedFailure # TODO: RUSTPYTHON
593+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 'but got expr()' not found in 'expected some sort of expr, but got <_ast.expr object at 0x7e911a9a0>'
594594
def test_invalid_sum(self):
595595
pos = dict(lineno=2, col_offset=3)
596596
m = ast.Module([ast.Expr(ast.expr(**pos), **pos)], [])
597597
with self.assertRaises(TypeError) as cm:
598598
compile(m, "<test>", "exec")
599599
self.assertIn("but got expr()", str(cm.exception))
600600

601-
@unittest.expectedFailure # TODO: RUSTPYTHON
601+
@unittest.expectedFailure # TODO: RUSTPYTHON; ValueError: expected str for name
602602
def test_invalid_identifier(self):
603603
m = ast.Module([ast.Expr(ast.Name(42, ast.Load()))], [])
604604
ast.fix_missing_locations(m)
@@ -615,7 +615,7 @@ def test_invalid_constant(self):
615615
):
616616
compile(e, "<test>", "eval")
617617

618-
@unittest.expectedFailure # TODO: RUSTPYTHON
618+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: expected some sort of expr, but got None
619619
def test_empty_yield_from(self):
620620
# Issue 16546: yield from value is not optional.
621621
empty_yield_from = ast.parse("def f():\n yield from g()")
@@ -670,7 +670,7 @@ def test_issue39579_dotted_name_end_col_offset(self):
670670
attr_b = tree.body[0].decorator_list[0].value
671671
self.assertEqual(attr_b.end_col_offset, 4)
672672

673-
@unittest.expectedFailure # TODO: RUSTPYTHON
673+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: None != 'withitem(expr context_expr, expr? optional_vars)'
674674
def test_ast_asdl_signature(self):
675675
self.assertEqual(ast.withitem.__doc__, "withitem(expr context_expr, expr? optional_vars)")
676676
self.assertEqual(ast.GtE.__doc__, "GtE")
@@ -776,7 +776,6 @@ def test_compare_fieldless(self):
776776
del a2.id
777777
self.assertTrue(ast.compare(a1, a2))
778778

779-
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: type object '_ast.Module' has no attribute '_field_types'
780779
def test_compare_modes(self):
781780
for mode, sources in (
782781
("exec", exec_tests),
@@ -1100,10 +1099,6 @@ def test_tstring(self):
11001099
self.assertIsInstance(tree.body[0].value.values[0], ast.Constant)
11011100
self.assertIsInstance(tree.body[0].value.values[1], ast.Interpolation)
11021101

1103-
@unittest.expectedFailure # TODO: RUSTPYTHON
1104-
def test_classattrs_deprecated(self):
1105-
return super().test_classattrs_deprecated()
1106-
11071102
@unittest.expectedFailure # TODO: RUSTPYTHON; ValueError: compile() unrecognized flags
11081103
def test_optimization_levels_const_folding(self):
11091104
return super().test_optimization_levels_const_folding()
@@ -1472,7 +1467,6 @@ def test_replace_reject_unknown_instance_fields(self):
14721467
class ASTHelpers_Test(unittest.TestCase):
14731468
maxDiff = None
14741469

1475-
@unittest.expectedFailure # TODO: RUSTPYTHON
14761470
def test_parse(self):
14771471
a = ast.parse('foo(1 + 1)')
14781472
b = compile('foo(1 + 1)', '<unknown>', 'exec', ast.PyCF_ONLY_AST)
@@ -1486,7 +1480,7 @@ def test_parse_in_error(self):
14861480
ast.literal_eval(r"'\U'")
14871481
self.assertIsNotNone(e.exception.__context__)
14881482

1489-
@unittest.expectedFailure # TODO: RUSTPYTHON
1483+
@unittest.expectedFailure # TODO: RUSTPYTHON; + Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load()), args=[Name(id='eggs', ctx=Load()), Constant(value='and cheese')]))])
14901484
def test_dump(self):
14911485
node = ast.parse('spam(eggs, "and cheese")')
14921486
self.assertEqual(ast.dump(node),
@@ -1507,7 +1501,7 @@ def test_dump(self):
15071501
"lineno=1, col_offset=0, end_lineno=1, end_col_offset=24)])"
15081502
)
15091503

1510-
@unittest.expectedFailure # TODO: RUSTPYTHON
1504+
@unittest.expectedFailure # TODO: RUSTPYTHON; - type_ignores=[])
15111505
def test_dump_indent(self):
15121506
node = ast.parse('spam(eggs, "and cheese")')
15131507
self.assertEqual(ast.dump(node, indent=3), """\
@@ -1563,7 +1557,7 @@ def test_dump_indent(self):
15631557
end_lineno=1,
15641558
end_col_offset=24)])""")
15651559

1566-
@unittest.expectedFailure # TODO: RUSTPYTHON
1560+
@unittest.expectedFailure # TODO: RUSTPYTHON; + Raise()
15671561
def test_dump_incomplete(self):
15681562
node = ast.Raise(lineno=3, col_offset=4)
15691563
self.assertEqual(ast.dump(node),
@@ -1731,7 +1725,7 @@ def check_text(code, empty, full, **kwargs):
17311725
full="Module(body=[Import(names=[alias(name='_ast', asname='ast')]), ImportFrom(module='module', names=[alias(name='sub')], level=0)], type_ignores=[])",
17321726
)
17331727

1734-
@unittest.expectedFailure # TODO: RUSTPYTHON
1728+
@unittest.expectedFailure # TODO: RUSTPYTHON; ? ^^^^^^^^^ ^^^^^^^^^
17351729
def test_copy_location(self):
17361730
src = ast.parse('1 + 1', mode='eval')
17371731
src.body.right = ast.copy_location(ast.Constant(2), src.body.right)
@@ -1749,7 +1743,7 @@ def test_copy_location(self):
17491743
self.assertEqual(new.lineno, 1)
17501744
self.assertEqual(new.col_offset, 1)
17511745

1752-
@unittest.expectedFailure # TODO: RUSTPYTHON
1746+
@unittest.expectedFailure # TODO: RUSTPYTHON; + Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=5), args=[Constant(value='spam', lineno=1, col_offset=6, end_lineno=1, end_col_offset=12)], lineno=1, col_offset=0, end_lineno=1, end_col_offset=13), lineno=1, col_offset=0, end_lineno=1, end_col_offset=13), Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=0), args=[Constant(value='eggs', lineno=1, col_offset=0, end_lineno=1, end_col_offset=0)], lineno=1, col_offset=0, end_lineno=1, end_col_offset=0), lineno=1, col_offset=0, end_lineno=1, end_col_offset=0)])
17531747
def test_fix_missing_locations(self):
17541748
src = ast.parse('write("spam")')
17551749
src.body.append(ast.Expr(ast.Call(ast.Name('spam', ast.Load()),
@@ -1769,7 +1763,7 @@ def test_fix_missing_locations(self):
17691763
"end_col_offset=0), lineno=1, col_offset=0, end_lineno=1, end_col_offset=0)])"
17701764
)
17711765

1772-
@unittest.expectedFailure # TODO: RUSTPYTHON
1766+
@unittest.expectedFailure # TODO: RUSTPYTHON; ? ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17731767
def test_increment_lineno(self):
17741768
src = ast.parse('1 + 1', mode='eval')
17751769
self.assertEqual(ast.increment_lineno(src, n=3), src)
@@ -1813,7 +1807,7 @@ def test_iter_fields(self):
18131807
self.assertEqual(d.pop('func').id, 'foo')
18141808
self.assertEqual(d, {'keywords': [], 'args': []})
18151809

1816-
@unittest.expectedFailure # TODO: RUSTPYTHON
1810+
@unittest.expectedFailure # TODO: RUSTPYTHON; + keyword(arg='eggs', value=Constant(value='leek'))
18171811
def test_iter_child_nodes(self):
18181812
node = ast.parse("spam(23, 42, eggs='leek')", mode='eval')
18191813
self.assertEqual(len(list(ast.iter_child_nodes(node.body))), 4)
@@ -1966,7 +1960,7 @@ def test_literal_eval_malformed_dict_nodes(self):
19661960
malformed = ast.Dict(keys=[ast.Constant(1)], values=[ast.Constant(2), ast.Constant(3)])
19671961
self.assertRaises(ValueError, ast.literal_eval, malformed)
19681962

1969-
@unittest.expectedFailure # TODO: RUSTPYTHON
1963+
@unittest.expectedFailure # TODO: RUSTPYTHON; SyntaxError: expected an expression
19701964
def test_literal_eval_trailing_ws(self):
19711965
self.assertEqual(ast.literal_eval(" -1"), -1)
19721966
self.assertEqual(ast.literal_eval("\t\t-1"), -1)
@@ -1985,15 +1979,15 @@ def test_literal_eval_malformed_lineno(self):
19851979
with self.assertRaisesRegex(ValueError, msg):
19861980
ast.literal_eval(node)
19871981

1988-
@unittest.expectedFailure # TODO: RUSTPYTHON
1982+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: "unexpected indent" does not match "expected an expression (<unknown>, line 2)"
19891983
def test_literal_eval_syntax_errors(self):
19901984
with self.assertRaisesRegex(SyntaxError, "unexpected indent"):
19911985
ast.literal_eval(r'''
19921986
\
19931987
(\
19941988
\ ''')
19951989

1996-
@unittest.expectedFailure # TODO: RUSTPYTHON
1990+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: required field "lineno" missing from alias
19971991
def test_bad_integer(self):
19981992
# issue13436: Bad error message with invalid numeric values
19991993
body = [ast.ImportFrom(module='time',
@@ -2222,7 +2216,7 @@ def test_if(self):
22222216
[ast.Expr(ast.Name("x", ast.Store()))])
22232217
self.stmt(i, "must have Load context")
22242218

2225-
@unittest.expectedFailure # TODO: RUSTPYTHON
2219+
@unittest.expectedFailure # TODO: RUSTPYTHON; SyntaxError: empty items on With
22262220
def test_with(self):
22272221
p = ast.Pass()
22282222
self.stmt(ast.With([], [p]), "empty items on With")
@@ -2263,7 +2257,7 @@ def test_try(self):
22632257
t = ast.Try([p], e, [p], [ast.Expr(ast.Name("x", ast.Store()))])
22642258
self.stmt(t, "must have Load context")
22652259

2266-
@unittest.expectedFailure # TODO: RUSTPYTHON
2260+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: ValueError not raised
22672261
def test_try_star(self):
22682262
p = ast.Pass()
22692263
t = ast.TryStar([], [], [], [p])
@@ -2296,7 +2290,7 @@ def test_assert(self):
22962290
def test_import(self):
22972291
self.stmt(ast.Import([]), "empty names on Import")
22982292

2299-
@unittest.expectedFailure # TODO: RUSTPYTHON
2293+
@unittest.expectedFailure # TODO: RUSTPYTHON; OverflowError: Python int too large to convert to Rust u32
23002294
def test_importfrom(self):
23012295
imp = ast.ImportFrom(None, [ast.alias("x", None)], -42)
23022296
self.stmt(imp, "Negative ImportFrom level")
@@ -2354,7 +2348,7 @@ def test_dict(self):
23542348
d = ast.Dict([ast.Name("x", ast.Load())], [None])
23552349
self.expr(d, "None disallowed")
23562350

2357-
@unittest.expectedFailure # TODO: RUSTPYTHON
2351+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: expected some sort of expr, but got None
23582352
def test_set(self):
23592353
self.expr(ast.Set([None]), "None disallowed")
23602354
s = ast.Set([ast.Name("x", ast.Store())])
@@ -2412,7 +2406,7 @@ def factory(comps):
24122406
return ast.DictComp(k, v, comps)
24132407
self._check_comprehension(factory)
24142408

2415-
@unittest.expectedFailure # TODO: RUSTPYTHON
2409+
@unittest.expectedFailure # TODO: RUSTPYTHON; SyntaxError: 'yield' outside function
24162410
def test_yield(self):
24172411
self.expr(ast.Yield(ast.Name("x", ast.Store())), "must have Load")
24182412
self.expr(ast.YieldFrom(ast.Name("x", ast.Store())), "must have Load")
@@ -2478,11 +2472,11 @@ def _sequence(self, fac):
24782472
self.expr(fac([ast.Name("x", ast.Store())], ast.Load()),
24792473
"must have Load context")
24802474

2481-
@unittest.expectedFailure # TODO: RUSTPYTHON
2475+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: expected some sort of expr, but got None
24822476
def test_list(self):
24832477
self._sequence(ast.List)
24842478

2485-
@unittest.expectedFailure # TODO: RUSTPYTHON
2479+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: expected some sort of expr, but got None
24862480
def test_tuple(self):
24872481
self._sequence(ast.Tuple)
24882482

@@ -3264,7 +3258,7 @@ def visit_Call(self, node: ast.Call):
32643258
class ASTConstructorTests(unittest.TestCase):
32653259
"""Test the autogenerated constructors for AST nodes."""
32663260

3267-
@unittest.expectedFailure # TODO: RUSTPYTHON
3261+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: DeprecationWarning not triggered
32683262
def test_FunctionDef(self):
32693263
args = ast.arguments()
32703264
self.assertEqual(args.args, [])
@@ -3278,7 +3272,7 @@ def test_FunctionDef(self):
32783272
self.assertEqual(node.name, 'foo')
32793273
self.assertEqual(node.decorator_list, [])
32803274

3281-
@unittest.expectedFailure # TODO: RUSTPYTHON
3275+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: None is not an instance of <class '_ast.Load'>
32823276
def test_expr_context(self):
32833277
name = ast.Name("x")
32843278
self.assertEqual(name.id, "x")
@@ -3382,7 +3376,7 @@ class BadFields(ast.AST):
33823376
with self.assertWarnsRegex(DeprecationWarning, r"Field b'\\xff\\xff.*' .*"):
33833377
obj = BadFields()
33843378

3385-
@unittest.expectedFailure # TODO: RUSTPYTHON
3379+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: None != []
33863380
def test_complete_field_types(self):
33873381
class _AllFieldTypes(ast.AST):
33883382
_fields = ('a', 'b')
@@ -3508,7 +3502,6 @@ def check_output(self, source, expect, *flags):
35083502
expect = self.text_normalize(expect)
35093503
self.assertEqual(res, expect)
35103504

3511-
@unittest.expectedFailure # TODO: RUSTPYTHON
35123505
@support.requires_resource('cpu')
35133506
def test_invocation(self):
35143507
# test various combinations of parameters

Lib/test/test_exception_group.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ def test_exception_group_types(self):
99
self.assertTrue(issubclass(ExceptionGroup, BaseExceptionGroup))
1010
self.assertTrue(issubclass(BaseExceptionGroup, BaseException))
1111

12-
# TODO: RUSTPYTHON
13-
@unittest.expectedFailure
1412
def test_exception_is_not_generic_type(self):
1513
with self.assertRaisesRegex(TypeError, 'Exception'):
1614
Exception[OSError]

Lib/test/test_genericalias.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def test_subscriptable(self):
151151
self.assertEqual(alias.__args__, (int,))
152152
self.assertEqual(alias.__parameters__, ())
153153

154-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
155154
def test_unsubscriptable(self):
156155
for t in int, str, float, Sized, Hashable:
157156
tname = t.__name__
@@ -365,7 +364,6 @@ def test_type_generic(self):
365364
self.assertEqual(t(test), Test)
366365
self.assertEqual(t(0), int)
367366

368-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
369367
def test_type_subclass_generic(self):
370368
class MyType(type):
371369
pass

crates/codegen/src/unparse.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
363363
self.p(")")?;
364364
}
365365
ast::Expr::FString(ast::ExprFString { value, .. }) => self.unparse_fstring(value)?,
366-
ast::Expr::TString(ast::ExprTString { value, .. }) => {
367-
self.unparse_tstring(value)?
368-
}
366+
ast::Expr::TString(ast::ExprTString { value, .. }) => self.unparse_tstring(value)?,
369367
ast::Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
370368
if value.is_unicode() {
371369
self.p("u")?

crates/vm/src/stdlib/ast/expression.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,18 +336,27 @@ impl Node for ast::ExprLambda {
336336
.into_ref_with_type(vm, pyast::NodeArguments::static_type().to_owned())
337337
.unwrap();
338338
let args_dict = args_node.as_object().dict().unwrap();
339-
args_dict.set_item("posonlyargs", vm.ctx.new_list(vec![]).into(), vm).unwrap();
340-
args_dict.set_item("args", vm.ctx.new_list(vec![]).into(), vm).unwrap();
339+
args_dict
340+
.set_item("posonlyargs", vm.ctx.new_list(vec![]).into(), vm)
341+
.unwrap();
342+
args_dict
343+
.set_item("args", vm.ctx.new_list(vec![]).into(), vm)
344+
.unwrap();
341345
args_dict.set_item("vararg", vm.ctx.none(), vm).unwrap();
342-
args_dict.set_item("kwonlyargs", vm.ctx.new_list(vec![]).into(), vm).unwrap();
343-
args_dict.set_item("kw_defaults", vm.ctx.new_list(vec![]).into(), vm).unwrap();
346+
args_dict
347+
.set_item("kwonlyargs", vm.ctx.new_list(vec![]).into(), vm)
348+
.unwrap();
349+
args_dict
350+
.set_item("kw_defaults", vm.ctx.new_list(vec![]).into(), vm)
351+
.unwrap();
344352
args_dict.set_item("kwarg", vm.ctx.none(), vm).unwrap();
345-
args_dict.set_item("defaults", vm.ctx.new_list(vec![]).into(), vm).unwrap();
353+
args_dict
354+
.set_item("defaults", vm.ctx.new_list(vec![]).into(), vm)
355+
.unwrap();
346356
args_node.into()
347357
}
348358
};
349-
dict.set_item("args", args, vm)
350-
.unwrap();
359+
dict.set_item("args", args, vm).unwrap();
351360
dict.set_item("body", body.ast_to_object(vm, source_file), vm)
352361
.unwrap();
353362
node_add_location(&dict, _range, vm, source_file);

crates/vm/src/stdlib/ast/parameter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ impl Node for ast::Parameter {
127127
)
128128
.unwrap();
129129
// Ruff AST doesn't track type_comment, so always set to None
130-
dict.set_item("type_comment", _vm.ctx.none(), _vm)
131-
.unwrap();
130+
dict.set_item("type_comment", _vm.ctx.none(), _vm).unwrap();
132131
node_add_location(&dict, range, _vm, source_file);
133132
node.into()
134133
}

crates/vm/src/stdlib/ast/python.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ pub(crate) mod _ast {
8989

9090
// Set default values only for built-in AST nodes (_field_types present).
9191
// Custom AST subclasses without _field_types do NOT get automatic defaults.
92-
let has_field_types = zelf.class().get_attr(vm.ctx.intern_str("_field_types")).is_some();
92+
let has_field_types = zelf
93+
.class()
94+
.get_attr(vm.ctx.intern_str("_field_types"))
95+
.is_some();
9396
if has_field_types {
9497
// ASDL list fields (type*) default to empty list,
9598
// optional fields (type?) default to None.

0 commit comments

Comments
 (0)