Repository: sympy/sympy

Issue:
Broken pretty printing for ConditionSet(x, Eq(-x + exp(x), 0), Complexes)
```py
>>> print(solveset(exp(x) - x, x))
ConditionSet(x, Eq(-x + exp(x), 0), Complexes)
>>> pprint(solveset(exp(x) - x, x))
{x | x ∊ ℂ ∧ (      x    , -x + ℯ  = 0)}
```

In 1.5.1 it is correct.

```py
>>> print(solveset(exp(x) - x, x))
ConditionSet(x, Eq(-x + exp(x), 0), Complexes)
>>> pprint(solveset(exp(x) - x, x))
⎧                  x    ⎫
⎨x | x ∊ ℂ ∧ -x + ℯ  = 0⎬
⎩                       ⎭
```

I bisected it to 22313ea0d8a746cc6860117c6dbea8de0f095789. CC @oscarbenjamin 

Discussion:
sympy-bot: 

Hi, I am the [SymPy bot](https://github.com/sympy/sympy-bot) (v149). I'm here to help you write a release notes entry. Please read the [guide on how to write release notes](https://github.com/sympy/sympy/wiki/Writing-Release-Notes).

:x: There was an issue with the release notes. **Please do not close this pull request;** instead edit the description after reading the [guide on how to write release notes](https://github.com/sympy/sympy/wiki/Writing-Release-Notes).

* No release notes were found. Please edit the PR description and write the release notes under `<!-- BEGIN RELEASE NOTES -->`.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. <details><summary>Click here to see the pull request description that was parsed.</summary>

    <!-- Your title above should be a short description of what
    was changed. Do not include the issue number in the title. -->

    #### References to other Issues or PRs
    <!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
    format, e.g. "Fixes #1234". See
    https://github.com/blog/1506-closing-issues-via-pull-requests . Please also
    write a comment on that issue linking back to this pull request once it is
    open. -->
    Fixes #18272 and Fixes #17339

    #### Brief description of what is fixed or changed


    #### Other comments


    #### Release Notes

    <!-- Write the release notes for this release below. See
    https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
    on how to write release notes. The bot will check your release notes
    automatically to see if they are formatted correctly. -->

    <!-- BEGIN RELEASE NOTES -->

    <!-- END RELEASE NOTES -->


</details><p>

V1krant: @oscarbenjamin, The test case for this issue passes on my computer but is failing in Travis. Could you please help me out and let me know what could be going wrong?
oscarbenjamin: I get a test failure on my computer:
```
$ pytest sympy/printing/pretty/tests/test_pretty.py::test_issue_18272
========================================== test session starts ==========================================
platform linux -- Python 3.6.9, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
architecture: 64-bit
cache:        yes
ground types: gmpy 2.0.8

rootdir: /space/enojb/sympy/sympy.git, inifile: pytest.ini
plugins: forked-1.0.2, xdist-1.29.0, instafail-0.4.1
collected 1 item                                                                                        

sympy/printing/pretty/tests/test_pretty.py F                                                      [100%]

=============================================== FAILURES ================================================
___________________________________________ test_issue_18272 ____________________________________________

    def test_issue_18272():
        from sympy.solvers import solveset
        from sympy import pretty, ConditionSet
        x = Symbol('x')
        n = Symbol('n')
    
>       assert pretty(solveset(exp(x) - x, x)) == \
        '⎧            ⎛      x    ⎞⎫\n'\
        '⎨x | x ∊ ℂ ∧ ⎝-x + ℯ  = 0⎠⎬\n'\
        '⎩                         ⎭'
E       AssertionError: assert '            ... -x + e  = 0}' == '⎧            ...            ⎭'
E         -                                 x     
E         - {x | x in S.Complexes and -x + e  = 0}
E         + ⎧            ⎛      x    ⎞⎫
E         + ⎨x | x ∊ ℂ ∧ ⎝-x + ℯ  = 0⎠⎬
E         + ⎩                         ⎭

sympy/printing/pretty/tests/test_pretty.py:6944: AssertionError
                                            DO *NOT* COMMIT!                                            
======================================= 1 failed in 2.49 seconds ========================================
```
This is happening in the optional dependency tests so it might depend which other packages you have installed or on the environment where you run the tests.

Patch:
diff --git a/sympy/printing/pretty/pretty.py b/sympy/printing/pretty/pretty.py
index 1393a7b347..75562875b8 100644
--- a/sympy/printing/pretty/pretty.py
+++ b/sympy/printing/pretty/pretty.py
@@ -2058,7 +2058,8 @@ def _print_ConditionSet(self, ts):
         else:
             cond = self._print(ts.condition)
             if self._use_unicode:
-                cond = self._print_seq(cond, "(", ")")
+                cond = self._print(cond)
+                cond = prettyForm(*cond.parens())
 
         bar = self._print("|")
 


Test patch:
diff --git a/sympy/printing/pretty/tests/test_pretty.py b/sympy/printing/pretty/tests/test_pretty.py
index 2be7a4ff76..8c492a9a60 100644
--- a/sympy/printing/pretty/tests/test_pretty.py
+++ b/sympy/printing/pretty/tests/test_pretty.py
@@ -32,6 +32,7 @@
 from sympy.physics.units import joule, degree
 from sympy.printing.pretty import pprint, pretty as xpretty
 from sympy.printing.pretty.pretty_symbology import center_accent, is_combining
+from sympy import ConditionSet
 
 from sympy.sets import ImageSet, ProductSet
 from sympy.sets.setexpr import SetExpr
@@ -6934,3 +6935,29 @@ def test_is_combining():
 def test_issue_17857():
     assert pretty(Range(-oo, oo)) == '{..., -1, 0, 1, ...}'
     assert pretty(Range(oo, -oo, -1)) == '{..., 1, 0, -1, ...}'
+
+def test_issue_18272():
+    x = Symbol('x')
+    n = Symbol('n')
+
+    assert upretty(ConditionSet(x, Eq(-x + exp(x), 0), S.Complexes)) == \
+    '⎧            ⎛      x    ⎞⎫\n'\
+    '⎨x | x ∊ ℂ ∧ ⎝-x + ℯ  = 0⎠⎬\n'\
+    '⎩                         ⎭'
+    assert upretty(ConditionSet(x, Contains(n/2, Interval(0, oo)), FiniteSet(-n/2, n/2))) == \
+    '⎧        ⎧-n   n⎫   ⎛n         ⎞⎫\n'\
+    '⎨x | x ∊ ⎨───, ─⎬ ∧ ⎜─ ∈ [0, ∞)⎟⎬\n'\
+    '⎩        ⎩ 2   2⎭   ⎝2         ⎠⎭'
+    assert upretty(ConditionSet(x, Eq(Piecewise((1, x >= 3), (x/2 - 1/2, x >= 2), (1/2, x >= 1),
+                (x/2, True)) - 1/2, 0), Interval(0, 3))) == \
+    '⎧                 ⎛⎛⎧   1     for x ≥ 3⎞          ⎞⎫\n'\
+    '⎪                 ⎜⎜⎪                  ⎟          ⎟⎪\n'\
+    '⎪                 ⎜⎜⎪x                 ⎟          ⎟⎪\n'\
+    '⎪                 ⎜⎜⎪─ - 0.5  for x ≥ 2⎟          ⎟⎪\n'\
+    '⎪                 ⎜⎜⎪2                 ⎟          ⎟⎪\n'\
+    '⎨x | x ∊ [0, 3] ∧ ⎜⎜⎨                  ⎟ - 0.5 = 0⎟⎬\n'\
+    '⎪                 ⎜⎜⎪  0.5    for x ≥ 1⎟          ⎟⎪\n'\
+    '⎪                 ⎜⎜⎪                  ⎟          ⎟⎪\n'\
+    '⎪                 ⎜⎜⎪   x              ⎟          ⎟⎪\n'\
+    '⎪                 ⎜⎜⎪   ─     otherwise⎟          ⎟⎪\n'\
+    '⎩                 ⎝⎝⎩   2              ⎠          ⎠⎭'