diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-09-27 14:42:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-27 14:42:37 (GMT) |
commit | 3f22811fef73aec848d961593d95fa877f77ecbf (patch) | |
tree | 025ca176b2993e8d85a0961f994794c3f9801032 /Tools/parser | |
parent | a94ee12c26aa8dd7dce01373779df8055aff765b (diff) | |
download | cpython-3f22811fef73aec848d961593d95fa877f77ecbf.zip cpython-3f22811fef73aec848d961593d95fa877f77ecbf.tar.gz cpython-3f22811fef73aec848d961593d95fa877f77ecbf.tar.bz2 |
bpo-32892: Use ast.Constant instead of specific constant AST types. (GH-9445)
Diffstat (limited to 'Tools/parser')
-rw-r--r-- | Tools/parser/unparse.py | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py index 7e1cc4e..82c3c77 100644 --- a/Tools/parser/unparse.py +++ b/Tools/parser/unparse.py @@ -329,12 +329,6 @@ class Unparser: self.leave() # expr - def _Bytes(self, t): - self.write(repr(t.s)) - - def _Str(self, tree): - self.write(repr(tree.s)) - def _JoinedStr(self, t): self.write("f") string = io.StringIO() @@ -352,10 +346,6 @@ class Unparser: meth = getattr(self, "_fstring_" + type(value).__name__) meth(value, write) - def _fstring_Str(self, t, write): - value = t.s.replace("{", "{{").replace("}", "}}") - write(value) - def _fstring_Constant(self, t, write): assert isinstance(t.value, str) value = t.value.replace("{", "{{").replace("}", "}}") @@ -384,6 +374,7 @@ class Unparser: def _write_constant(self, value): if isinstance(value, (float, complex)): + # Substitute overflowing decimal literal for AST infinities. self.write(repr(value).replace("inf", INFSTR)) else: self.write(repr(value)) @@ -398,16 +389,11 @@ class Unparser: else: interleave(lambda: self.write(", "), self._write_constant, value) self.write(")") + elif value is ...: + self.write("...") else: self._write_constant(t.value) - def _NameConstant(self, t): - self.write(repr(t.value)) - - def _Num(self, t): - # Substitute overflowing decimal literal for AST infinities. - self.write(repr(t.n).replace("inf", INFSTR)) - def _List(self, t): self.write("[") interleave(lambda: self.write(", "), self.dispatch, t.elts) @@ -539,8 +525,7 @@ class Unparser: # Special case: 3.__abs__() is a syntax error, so if t.value # is an integer literal then we need to either parenthesize # it or add an extra space to get 3 .__abs__(). - if ((isinstance(t.value, ast.Num) and isinstance(t.value.n, int)) - or (isinstance(t.value, ast.Constant) and isinstance(t.value.value, int))): + if isinstance(t.value, ast.Constant) and isinstance(t.value.value, int): self.write(" ") self.write(".") self.write(t.attr) |