diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-03-26 15:12:09 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-03-26 15:15:07 +0200 |
| commit | 6ef362c490bc2608c971eeabd5930ea0d8893dbe (patch) | |
| tree | d745b8b5427b5831998b289dc30bd0a75fe2d6be /kconfiglib.py | |
| parent | 7374891d0a9b455ff7d20e84efd0e6b1e3705c11 (diff) | |
Refactor expr_str() cases
- Detect Symbol directly instead of as (not tuple) + (not choice)
- Test explicitly for a tuple (non-Symbol) in NOT
- Add some tests to get better coverage for NOT and parentheses
Diffstat (limited to 'kconfiglib.py')
| -rw-r--r-- | kconfiglib.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index ed945ca..46da1c1 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -4106,23 +4106,20 @@ def expr_str(expr): Passing subexpressions of expressions to this function works as expected. """ - if not isinstance(expr, tuple): - if isinstance(expr, Choice): - if expr.name is not None: - return "<choice {}>".format(expr.name) - return "<choice>" - - # Symbol - + if isinstance(expr, Symbol): if expr.is_constant: return '"{}"'.format(escape(expr.name)) - return expr.name + if isinstance(expr, Choice): + if expr.name is not None: + return "<choice {}>".format(expr.name) + return "<choice>" + if expr[0] == NOT: - if isinstance(expr[1], Symbol): - return "!" + expr_str(expr[1]) - return "!({})".format(expr_str(expr[1])) + if isinstance(expr[1], tuple): + return "!({})".format(expr_str(expr[1])) + return "!" + expr_str(expr[1]) # Symbol if expr[0] == AND: return "{} && {}".format(_format_and_op(expr[1]), |
