+
+cimport cython
+
+@cython.test_assert_path_exists("//PythonCapiCallNode")
+@cython.test_fail_if_path_exists("//AttributeNode")
def get(dict d, key):
"""
>>> d = { 1: 10 }
"""
return d.get(key)
+
+@cython.test_assert_path_exists("//PythonCapiCallNode")
+@cython.test_fail_if_path_exists("//AttributeNode")
def get_default(dict d, key, default):
"""
>>> d = { 1: 10 }
ValueError
"""
return d.get(key, default)
+
+
+@cython.test_assert_path_exists("//PythonCapiCallNode")
+@cython.test_fail_if_path_exists("//AttributeNode")
+def get_in_condition(dict d, key, expected_result):
+ """
+ >>> d = dict(a=1, b=2)
+ >>> getitem_in_condition(d, 'a', 1)
+ True
+ """
+ return d.get(key) is expected_result
cdef class Subscriptable:
def __getitem__(self, key):
return key
+
+
+def getitem_in_condition(dict d, key, expected_result):
+ """
+ >>> d = dict(a=1, b=2)
+ >>> getitem_in_condition(d, 'a', 1)
+ True
+ """
+ return d[key] is expected_result