forked from clj-python/libpython-clj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
57 lines (39 loc) · 1.35 KB
/
__init__.py
File metadata and controls
57 lines (39 loc) · 1.35 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class WithObjClass:
def __init__(self, suppress, fn_list):
self.suppress = suppress
self.fn_list = fn_list
def __enter__(self):
self.fn_list.append("enter")
return self # Return self so methods can be called on the bound variable
def doit_noerr(self):
return 1
def doit_err(self):
raise Exception("Spam", "Eggs")
def __exit__(self, ex_type, ex_val, ex_traceback):
self.fn_list.append("exit: " + str(ex_val))
return self.suppress
class FileWrapper:
"""Context manager where __enter__ returns a different object"""
def __init__(self, content):
self.content = content
def __enter__(self):
# Return a different object with the content
import io
return io.StringIO(self.content)
def __exit__(self, *args):
return False
def for_iter(arg):
retval = []
for item in arg:
retval.append(item)
return retval
def calling_custom_clojure_fn(arg):
return arg.clojure_fn()
def complex_fn(a, b, c: str = 5, *args, d=10, **kwargs):
return {"a": a, "b": b, "c": c, "args": args, "d": d, "kwargs": kwargs}
complex_fn_testcases = {
"complex_fn(1, 2, c=10, d=10, e=10)": complex_fn(1, 2, c=10, d=10, e=10),
"complex_fn(1, 2, 10, 11, 12, d=10, e=10)": complex_fn(
1, 2, 10, 11, 12, d=10, e=10
),
}