forked from spack/spack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unparser: implement operator precedence algorithm for unparser
Backport operator precedence algorithm from here: python/cpython@397b96f This eliminates unnecessary parentheses from our unparsed output and makes Spack's unparser consistent with the one in upstream Python 3.9+, with one exception. Our parser normalizes argument order when `py_ver_consistent` is set, so that star arguments in function calls come last. We have to do this because Python 2's AST doesn't have information about their actual order. If we ever support only Python 3.9 and higher, we can easily switch over to `ast.unparse`, as the unparsing is consistent except for this detail (modulo future changes to `ast.unparse`)
- Loading branch information
Showing
7 changed files
with
314 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2014-2021, Simon Percivall and Spack Project Developers. | ||
# | ||
# SPDX-License-Identifier: Python-2.0 | ||
# coding: utf-8 | ||
|
||
from __future__ import absolute_import | ||
|
||
from six.moves import cStringIO | ||
|
||
from .unparser import Unparser | ||
|
||
__version__ = '1.6.3' | ||
|
||
|
||
def unparse(tree, py_ver_consistent=False): | ||
v = cStringIO() | ||
unparser = Unparser(py_ver_consistent=py_ver_consistent) | ||
unparser.visit(tree, v) | ||
return v.getvalue().strip() + "\n" |
Oops, something went wrong.