Skip to content

Commit

Permalink
improve string ast
Browse files Browse the repository at this point in the history
  • Loading branch information
dvermd committed Oct 17, 2022
1 parent 1f9d852 commit 42887c1
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 118 deletions.
6 changes: 0 additions & 6 deletions Lib/test/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ def test_field_attr_writable(self):
x._fields = 666
self.assertEqual(x._fields, 666)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_classattrs(self):
x = ast.Num()
self.assertEqual(x._fields, ('value', 'kind'))
Expand Down Expand Up @@ -550,8 +548,6 @@ def test_module(self):
x = ast.Module(body, [])
self.assertEqual(x.body, body)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_nodeclasses(self):
# Zero arguments constructor explicitly allowed
x = ast.BinOp()
Expand Down Expand Up @@ -596,8 +592,6 @@ def test_nodeclasses(self):
x = ast.BinOp(1, 2, 3, foobarbaz=42)
self.assertEqual(x.foobarbaz, 42)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_no_fields(self):
# this used to fail because Sub._fields was None
x = ast.Sub()
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,8 @@ def func2():
"""
self._check_error(code, "expected ':'")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_invalid_line_continuation_error_position(self):
self._check_error(r"a = 3 \ 4",
"unexpected character after line continuation character",
Expand Down
2 changes: 1 addition & 1 deletion compiler/ast/asdl_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def gen_classdef(self, name, fields, attrs, depth, base="AstNode"):
f"ctx.new_str(ascii!({json.dumps(f.name)})).into()" for f in fields
)
self.emit(
f"class.set_attr(identifier!(ctx, _fields), ctx.new_list(vec![{fields}]).into());",
f"class.set_attr(identifier!(ctx, _fields), ctx.new_tuple(vec![{fields}]).into());",
depth + 2,
)
attrs = ",".join(
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Location {

pub fn reset(&mut self) {
self.row = 1;
self.column = 1;
self.column = 0;
}

pub fn go_right(&mut self) {
Expand Down
9 changes: 5 additions & 4 deletions vm/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl FormatSpec {
}
};

self.format_sign_and_align(&magnitude_string, sign_str)
self.format_sign_and_align(&magnitude_string, sign_str, FormatAlign::Right)
}

#[inline]
Expand Down Expand Up @@ -510,12 +510,12 @@ impl FormatSpec {
},
};

self.format_sign_and_align(&magnitude_string, sign_str)
self.format_sign_and_align(&magnitude_string, sign_str, FormatAlign::Right)
}

pub(crate) fn format_string(&self, s: &str) -> Result<String, &'static str> {
match self.format_type {
Some(FormatType::String) | None => self.format_sign_and_align(s, ""),
Some(FormatType::String) | None => self.format_sign_and_align(s, "", FormatAlign::Left),
_ => Err("Unknown format code for object of type 'str'"),
}
}
Expand All @@ -524,8 +524,9 @@ impl FormatSpec {
&self,
magnitude_string: &str,
sign_str: &str,
default_align: FormatAlign,
) -> Result<String, &'static str> {
let align = self.align.unwrap_or(FormatAlign::Right);
let align = self.align.unwrap_or(default_align);

// Use the byte length as the string length since we're in ascii
let num_chars = magnitude_string.len();
Expand Down

0 comments on commit 42887c1

Please sign in to comment.