Skip to content
Snippets Groups Projects
  • Todd Gamblin's avatar
    unparser: implement operator precedence algorithm for unparser · 396c37d8
    Todd Gamblin authored
    Backport operator precedence algorithm from here:
        https://github.com/python/cpython/commit/397b96f6d7a89f778ebc0591e32216a8183fe667
    
    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`)
    396c37d8