Repository: cython/cython

Issue:
[BUG] Compile error when calling function chosen by ternary in contextmanager
### Describe the bug

Present in the latest beta, as of writing. Not sure if present in other versions

Command:
cythonize -3 --inplace test.py

Traceback:
```
Compiling D:\Projects\_cython\test.py because it changed.
[1/1] Cythonizing D:\Projects\_cython\test.py

Error compiling Cython file:
------------------------------------------------------------
...

def main():
    flag = True
    # (foo if flag else baz)()             # OK
    # with foo() if flag else baz() as x:  # OK
    with (foo if flag else baz)() as x:    # ERROR
                               ^
------------------------------------------------------------

test.py:19:31: Expected ':', found '('
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Scripts\cythonize.exe\__main__.py", line 7, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\Cython\Build\Cythonize.py", line 243, in main
    _cython_compile_files(all_paths, options)
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\Cython\Build\Cythonize.py", line 70, in _cython_compile_files
    ext_modules = cythonize(
                  ^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\Cython\Build\Dependencies.py", line 1134, in cythonize
    cythonize_one(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\Cython\Build\Dependencies.py", line 1301, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: D:\Projects\_cython\test.py
```

### Code to reproduce the behaviour:

```cython
import contextlib
from typing import ContextManager


@contextlib.contextmanager
def foo() -> ContextManager[int]:
    yield 1


@contextlib.contextmanager
def baz() -> ContextManager[int]:
    yield 0


def main():
    flag = True
    # (foo if flag else baz)()             # OK
    # with foo() if flag else baz() as x:  # OK
    with (foo if flag else baz)() as x:    # ERROR
        print(x)


if __name__ == '__main__':
    main()
```


### Expected behaviour

Being valid python syntax, compilation should not have any error

### OS

Windows

### Python version

3.11.3

### Cython version

3.0.0b2

### Additional context

_No response_


Discussion:
Looks to work on 0.29.x so is a regression. Probably related to https://github.com/cython/cython/commit/9c6140b373334e9fa661582ccd1ffd816f1b622c

Resolving patch:
diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py
--- a/Cython/Compiler/Parsing.py
+++ b/Cython/Compiler/Parsing.py
@@ -2141,6 +2141,10 @@ def p_with_items(s, is_async=False):
             s.next()
             items = p_with_items_list(s, is_async)
             s.expect(")")
+            if s.sy != ":":
+                # Fail - the message doesn't matter because we'll try the
+                # non-bracket version so it'll never be shown
+                s.error("")
         brackets_succeeded = not errors
     if not brackets_succeeded:
         # try the non-bracket version


Test patch:
diff --git a/tests/run/withstat_py.py b/tests/run/withstat_py.py
--- a/tests/run/withstat_py.py
+++ b/tests/run/withstat_py.py
@@ -205,3 +205,23 @@ def manager_from_expression():
     g = GetManager()
     with g.get(2) as x:
         print(x)
+
+def manager_from_ternary(use_first):
+    """
+    >>> manager_from_ternary(True)
+    enter
+    exit <type 'type'> <type 'ValueError'> <type 'traceback'>
+    >>> manager_from_ternary(False)
+    enter
+    exit <type 'type'> <type 'ValueError'> <type 'traceback'>
+    In except
+    """
+    # This is mostly testing a parsing problem, hence the
+    # result of the ternary must be callable
+    cm1_getter = lambda: ContextManager("1", exit_ret=True)
+    cm2_getter = lambda: ContextManager("2")
+    try:
+        with (cm1_getter if use_first else cm2_getter)():
+            raise ValueError
+    except ValueError:
+        print("In except")