File: with_statement_module_level_T536.pyx

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (34 lines) | stat: -rw-r--r-- 742 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# ticket: t536

__doc__ = """
>>> inner_result
['ENTER']
>>> result  # doctest: +ELLIPSIS
['ENTER', ...EXIT (<...ValueError...>,...ValueError..., <traceback object at ...)...]

>>> inner_result_no_exc
['ENTER']
>>> result_no_exc
['ENTER', 'EXIT (None, None, None)']
"""

class ContextManager(object):
    def __init__(self, result):
        self.result = result
    def __enter__(self):
        self.result.append("ENTER")
    def __exit__(self, *values):
        self.result.append("EXIT %r" % (values,))
        return True

result_no_exc = []

with ContextManager(result_no_exc) as c:
    inner_result_no_exc = result_no_exc[:]

result = []

with ContextManager(result) as c:
    inner_result = result[:]
    raise ValueError('TEST')