Skip to content

Commit f2bfb78

Browse files
dvermdyouknowone
authored andcommitted
Fix ast types' _fields and use 0-based column
1 parent 0b08786 commit f2bfb78

File tree

63 files changed

+595
-650
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+595
-650
lines changed

Lib/test/test_ast.py

-28
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ def test_non_interned_future_from_ast(self):
339339
mod.body[0].module = " __future__ ".strip()
340340
compile(mod, "<test>", "exec")
341341

342-
# TODO: RUSTPYTHON
343-
@unittest.expectedFailure
344342
def test_alias(self):
345343
im = ast.parse("from bar import y").body[0]
346344
self.assertEqual(len(im.names), 1)
@@ -369,8 +367,6 @@ def test_base_classes(self):
369367
self.assertTrue(issubclass(ast.comprehension, ast.AST))
370368
self.assertTrue(issubclass(ast.Gt, ast.AST))
371369

372-
# TODO: RUSTPYTHON
373-
@unittest.expectedFailure
374370
def test_field_attr_existence(self):
375371
for name, item in ast.__dict__.items():
376372
if self._is_ast_node(name, item):
@@ -403,8 +399,6 @@ def test_field_attr_writable(self):
403399
x._fields = 666
404400
self.assertEqual(x._fields, 666)
405401

406-
# TODO: RUSTPYTHON
407-
@unittest.expectedFailure
408402
def test_classattrs(self):
409403
x = ast.Num()
410404
self.assertEqual(x._fields, ('value', 'kind'))
@@ -548,8 +542,6 @@ def test_module(self):
548542
x = ast.Module(body, [])
549543
self.assertEqual(x.body, body)
550544

551-
# TODO: RUSTPYTHON
552-
@unittest.expectedFailure
553545
def test_nodeclasses(self):
554546
# Zero arguments constructor explicitly allowed
555547
x = ast.BinOp()
@@ -594,8 +586,6 @@ def test_nodeclasses(self):
594586
x = ast.BinOp(1, 2, 3, foobarbaz=42)
595587
self.assertEqual(x.foobarbaz, 42)
596588

597-
# TODO: RUSTPYTHON
598-
@unittest.expectedFailure
599589
def test_no_fields(self):
600590
# this used to fail because Sub._fields was None
601591
x = ast.Sub()
@@ -698,8 +688,6 @@ def test_issue18374_binop_col_offset(self):
698688
self.assertEqual(grandchild_binop.end_col_offset, 3)
699689
self.assertEqual(grandchild_binop.end_lineno, 1)
700690

701-
# TODO: RUSTPYTHON
702-
@unittest.expectedFailure
703691
def test_issue39579_dotted_name_end_col_offset(self):
704692
tree = ast.parse('@a.b.c\ndef f(): pass')
705693
attr_b = tree.body[0].decorator_list[0].value
@@ -1043,8 +1031,6 @@ def test_elif_stmt_start_position_with_else(self):
10431031
self.assertEqual(elif_stmt.lineno, 3)
10441032
self.assertEqual(elif_stmt.col_offset, 0)
10451033

1046-
# TODO: RUSTPYTHON
1047-
@unittest.expectedFailure
10481034
def test_starred_expr_end_position_within_call(self):
10491035
node = ast.parse('f(*[0, 1])')
10501036
starred_expr = node.body[0].value.args[0]
@@ -1939,8 +1925,6 @@ def _parse_value(self, s):
19391925
# and a right hand side of an assignment statement.
19401926
return ast.parse(s).body[0].value
19411927

1942-
# TODO: RUSTPYTHON
1943-
@unittest.expectedFailure
19441928
def test_lambda(self):
19451929
s = 'lambda x, *y: None'
19461930
lam = self._parse_value(s)
@@ -1966,17 +1950,13 @@ def func(x: int,
19661950
self._check_content(s, fdef.args.kwarg, 'kwargs: Any')
19671951
self._check_content(s, fdef.args.kwarg.annotation, 'Any')
19681952

1969-
# TODO: RUSTPYTHON
1970-
@unittest.expectedFailure
19711953
def test_call(self):
19721954
s = 'func(x, y=2, **kw)'
19731955
call = self._parse_value(s)
19741956
self._check_content(s, call.func, 'func')
19751957
self._check_content(s, call.keywords[0].value, '2')
19761958
self._check_content(s, call.keywords[1].value, 'kw')
19771959

1978-
# TODO: RUSTPYTHON
1979-
@unittest.expectedFailure
19801960
def test_call_noargs(self):
19811961
s = 'x[0]()'
19821962
call = self._parse_value(s)
@@ -1995,8 +1975,6 @@ class C(A, B):
19951975
self._check_content(s, cdef.bases[1], 'B')
19961976
self._check_content(s, cdef.body[0], 'x: int = 0')
19971977

1998-
# TODO: RUSTPYTHON
1999-
@unittest.expectedFailure
20001978
def test_class_kw(self):
20011979
s = 'class S(metaclass=abc.ABCMeta): pass'
20021980
cdef = ast.parse(s).body[0]
@@ -2172,8 +2150,6 @@ def test_tuples(self):
21722150
self._check_content(s3, t3, '(1 , 2 )')
21732151
self._check_end_pos(tm, 3, 1)
21742152

2175-
# TODO: RUSTPYTHON
2176-
@unittest.expectedFailure
21772153
def test_attribute_spaces(self):
21782154
s = 'func(x. y .z)'
21792155
call = self._parse_value(s)
@@ -2192,8 +2168,6 @@ def test_redundant_parenthesis(self):
21922168
self.assertEqual(type(v).__name__, 'BinOp')
21932169
self._check_content(s2, v, 'a + b')
21942170

2195-
# TODO: RUSTPYTHON
2196-
@unittest.expectedFailure
21972171
def test_trailers_with_redundant_parenthesis(self):
21982172
tests = (
21992173
('( ( ( a ) ) ) ( )', 'Call'),
@@ -2211,8 +2185,6 @@ def test_trailers_with_redundant_parenthesis(self):
22112185
self.assertEqual(type(v).__name__, t)
22122186
self._check_content(s2, v, s)
22132187

2214-
# TODO: RUSTPYTHON
2215-
@unittest.expectedFailure
22162188
def test_displays(self):
22172189
s1 = '[{}, {1, }, {1, 2,} ]'
22182190
s2 = '{a: b, f (): g () ,}'

Lib/test/test_support.py

+2
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ def test_make_bad_fd(self):
315315
os.write(fd, b"foo")
316316
self.assertEqual(cm.exception.errno, errno.EBADF)
317317

318+
# TODO: RUSTPYTHON
319+
@unittest.expectedFailure
318320
def test_check_syntax_error(self):
319321
support.check_syntax_error(self, "def class", lineno=1, offset=5)
320322
with self.assertRaises(AssertionError):

Lib/test/test_syntax.py

+2
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,8 @@ def func2():
15411541
"""
15421542
self._check_error(code, "expected ':'")
15431543

1544+
# TODO: RUSTPYTHON
1545+
@unittest.expectedFailure
15441546
def test_invalid_line_continuation_error_position(self):
15451547
self._check_error(r"a = 3 \ 4",
15461548
"unexpected character after line continuation character",

Lib/test/test_tokenize.py

-30
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ def test_implicit_newline(self):
5858
self.assertEqual(tokens[-2].type, NEWLINE)
5959
self.assertEqual(tokens[-1].type, ENDMARKER)
6060

61-
# TODO: RUSTPYTHON
62-
@unittest.expectedFailure
6361
def test_basic(self):
6462
self.check_tokenize("1 + 1", """\
6563
NUMBER '1' (1, 0) (1, 1)
@@ -97,8 +95,6 @@ def k(x):
9795
for tok in tokenize(readline):
9896
pass
9997

100-
# TODO: RUSTPYTHON
101-
@unittest.expectedFailure
10298
def test_int(self):
10399
# Ordinary integers and binary operators
104100
self.check_tokenize("0xff <= 255", """\
@@ -156,8 +152,6 @@ def test_int(self):
156152
NUMBER '1234' (1, 14) (1, 18)
157153
""")
158154

159-
# TODO: RUSTPYTHON
160-
@unittest.expectedFailure
161155
def test_long(self):
162156
# Long integers
163157
self.check_tokenize("x = 0", """\
@@ -182,8 +176,6 @@ def test_long(self):
182176
NUMBER '15921590215012591' (1, 5) (1, 22)
183177
""")
184178

185-
# TODO: RUSTPYTHON
186-
@unittest.expectedFailure
187179
def test_float(self):
188180
# Floating point numbers
189181
self.check_tokenize("x = 3.14159", """\
@@ -239,8 +231,6 @@ def number_token(s):
239231
for lit in INVALID_UNDERSCORE_LITERALS:
240232
self.assertNotEqual(number_token(lit), lit)
241233

242-
# TODO: RUSTPYTHON
243-
@unittest.expectedFailure
244234
def test_string(self):
245235
# String literals
246236
self.check_tokenize("x = ''; y = \"\"", """\
@@ -407,8 +397,6 @@ def test_string(self):
407397
STRING 'Rf"abc\\\\\\ndef"' (1, 0) (2, 4)
408398
""")
409399

410-
# TODO: RUSTPYTHON
411-
@unittest.expectedFailure
412400
def test_function(self):
413401
self.check_tokenize("def d22(a, b, c=2, d=2, *k): pass", """\
414402
NAME 'def' (1, 0) (1, 3)
@@ -469,8 +457,6 @@ def test_function(self):
469457
NAME 'pass' (1, 34) (1, 38)
470458
""")
471459

472-
# TODO: RUSTPYTHON
473-
@unittest.expectedFailure
474460
def test_comparison(self):
475461
# Comparison
476462
self.check_tokenize("if 1 < 1 > 1 == 1 >= 5 <= 0x15 <= 0x12 != "
@@ -509,8 +495,6 @@ def test_comparison(self):
509495
NAME 'pass' (1, 84) (1, 88)
510496
""")
511497

512-
# TODO: RUSTPYTHON
513-
@unittest.expectedFailure
514498
def test_shift(self):
515499
# Shift
516500
self.check_tokenize("x = 1 << 1 >> 5", """\
@@ -523,8 +507,6 @@ def test_shift(self):
523507
NUMBER '5' (1, 14) (1, 15)
524508
""")
525509

526-
# TODO: RUSTPYTHON
527-
@unittest.expectedFailure
528510
def test_additive(self):
529511
# Additive
530512
self.check_tokenize("x = 1 - y + 15 - 1 + 0x124 + z + a[5]", """\
@@ -548,8 +530,6 @@ def test_additive(self):
548530
OP ']' (1, 36) (1, 37)
549531
""")
550532

551-
# TODO: RUSTPYTHON
552-
@unittest.expectedFailure
553533
def test_multiplicative(self):
554534
# Multiplicative
555535
self.check_tokenize("x = 1//1*1/5*12%0x12@42", """\
@@ -570,8 +550,6 @@ def test_multiplicative(self):
570550
NUMBER '42' (1, 21) (1, 23)
571551
""")
572552

573-
# TODO: RUSTPYTHON
574-
@unittest.expectedFailure
575553
def test_unary(self):
576554
# Unary
577555
self.check_tokenize("~1 ^ 1 & 1 |1 ^ -1", """\
@@ -609,8 +587,6 @@ def test_unary(self):
609587
NUMBER '1' (1, 22) (1, 23)
610588
""")
611589

612-
# TODO: RUSTPYTHON
613-
@unittest.expectedFailure
614590
def test_selector(self):
615591
# Selector
616592
self.check_tokenize("import sys, time\nx = sys.modules['time'].time()", """\
@@ -633,8 +609,6 @@ def test_selector(self):
633609
OP ')' (2, 29) (2, 30)
634610
""")
635611

636-
# TODO: RUSTPYTHON
637-
@unittest.expectedFailure
638612
def test_method(self):
639613
# Methods
640614
self.check_tokenize("@staticmethod\ndef foo(x,y): pass", """\
@@ -652,8 +626,6 @@ def test_method(self):
652626
NAME 'pass' (2, 14) (2, 18)
653627
""")
654628

655-
# TODO: RUSTPYTHON
656-
@unittest.expectedFailure
657629
def test_tabs(self):
658630
# Evil tabs
659631
self.check_tokenize("def f():\n"
@@ -703,8 +675,6 @@ def test_unicode(self):
703675
STRING "U'green'" (2, 7) (2, 15)
704676
""")
705677

706-
# TODO: RUSTPYTHON
707-
@unittest.expectedFailure
708678
def test_async(self):
709679
# Async/await extension:
710680
self.check_tokenize("async = 1", """\

Lib/test/test_unicode.py

-2
Original file line numberDiff line numberDiff line change
@@ -1390,8 +1390,6 @@ def test_format_huge_item_number(self):
13901390
with self.assertRaises(ValueError):
13911391
result = format_string.format(2.34)
13921392

1393-
# TODO: RUSTPYTHON
1394-
@unittest.expectedFailure
13951393
def test_format_auto_numbering(self):
13961394
class C:
13971395
def __init__(self, x=100):

compiler/ast/asdl_rs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def gen_classdef(self, name, fields, attrs, depth, base="AstNode"):
449449
f"ctx.new_str(ascii!({json.dumps(f.name)})).into()" for f in fields
450450
)
451451
self.emit(
452-
f"class.set_attr(identifier!(ctx, _fields), ctx.new_list(vec![{fields}]).into());",
452+
f"class.set_attr(identifier!(ctx, _fields), ctx.new_tuple(vec![{fields}]).into());",
453453
depth + 2,
454454
)
455455
attrs = ",".join(

compiler/core/src/location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Location {
4343

4444
pub fn reset(&mut self) {
4545
self.row = 1;
46-
self.column = 1;
46+
self.column = 0;
4747
}
4848

4949
pub fn go_right(&mut self) {

compiler/parser/src/parser.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ pub fn parse_program(source: &str, source_path: &str) -> Result<ast::Suite, Pars
3535
/// assert_eq!(
3636
/// expr,
3737
/// ast::Expr {
38-
/// location: ast::Location::new(1, 3),
39-
/// end_location: Some(ast::Location::new(1, 6)),
38+
/// location: ast::Location::new(1, 2),
39+
/// end_location: Some(ast::Location::new(1, 5)),
4040
/// custom: (),
4141
/// node: ast::ExprKind::BinOp {
4242
/// left: Box::new(ast::Expr {
43-
/// location: ast::Location::new(1, 1),
44-
/// end_location: Some(ast::Location::new(1, 2)),
43+
/// location: ast::Location::new(1, 0),
44+
/// end_location: Some(ast::Location::new(1, 1)),
4545
/// custom: (),
4646
/// node: ast::ExprKind::Constant {
4747
/// value: ast::Constant::Int(1.into()),
@@ -50,8 +50,8 @@ pub fn parse_program(source: &str, source_path: &str) -> Result<ast::Suite, Pars
5050
/// }),
5151
/// op: ast::Operator::Add,
5252
/// right: Box::new(ast::Expr {
53-
/// location: ast::Location::new(1, 5),
54-
/// end_location: Some(ast::Location::new(1, 6)),
53+
/// location: ast::Location::new(1, 4),
54+
/// end_location: Some(ast::Location::new(1, 5)),
5555
/// custom: (),
5656
/// node: ast::ExprKind::Constant {
5757
/// value: ast::Constant::Int(2.into()),

compiler/parser/src/snapshots/rustpython_parser__context__tests__ann_assign_name.snap

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)