@@ -72,9 +72,9 @@ def compile_module(self, name):
72
72
type ,
73
73
lambda : ([], 12 , sys .modules )
74
74
)
75
-
75
+
76
76
# Below are the PyObject_* identifiers that we know are used in numpy
77
-
77
+
78
78
def is_buffer (x ):
79
79
__breakpoint__ ()
80
80
if (isinstance (x , bytes ) or isinstance (x , bytearray ) or isinstance (x , array .array )):
@@ -103,7 +103,7 @@ def forgiving_len(o):
103
103
)
104
104
test_PyObject_Size = CPyExtFunction (
105
105
forgiving_len ,
106
- lambda : ([], [1 , 2 , 3 , 4 ], (1 ,), sys .modules ),
106
+ lambda : ([], [1 , 2 , 3 , 4 ], (1 ,), { 1 : 1 }, sys .modules ),
107
107
resultspec = "i" ,
108
108
)
109
109
# PyObject_MALLOC
@@ -130,7 +130,7 @@ def forgiving_len(o):
130
130
(kwonly_fun , tuple (), {"x" : 456 , "y" : 789 }),
131
131
(sum , ("hello, world" ,), None ),
132
132
(kwonly_fun , tuple (), None ),
133
- )
133
+ )
134
134
135
135
test_PyObject_Call = CPyExtFunction (
136
136
lambda args : args [0 ](* args [1 ], ** args [2 ]) if args [2 ] else args [0 ](* args [1 ], ** dict ()),
@@ -184,7 +184,7 @@ def forgiving_len(o):
184
184
argspec = "Os" ,
185
185
callfunction = "PyObject_CallFunction" ,
186
186
)
187
-
187
+
188
188
class MyObject ():
189
189
190
190
def foo (self , * args , ** kwargs ):
@@ -386,6 +386,18 @@ def setattrstring(args):
386
386
resultspec = "i" ,
387
387
cmpfunc = unhandled_error_compare
388
388
)
389
+ test_PyObject_HasAttr = CPyExtFunction (
390
+ lambda args : 1 if hasattr (* args ) else 0 ,
391
+ lambda : (
392
+ (TestPyObject .MyObject , "foo" ),
393
+ ([], "__len__" ),
394
+ ([], "foobar" ),
395
+ ),
396
+ arguments = ["PyObject* object" , "PyObject* attr" ],
397
+ argspec = "OO" ,
398
+ resultspec = "i" ,
399
+ )
400
+
389
401
test_PyObject_HasAttrString = CPyExtFunction (
390
402
lambda args : 1 if hasattr (* args ) else 0 ,
391
403
lambda : (
@@ -397,6 +409,23 @@ def setattrstring(args):
397
409
argspec = "Os" ,
398
410
resultspec = "i" ,
399
411
)
412
+
413
+ def _ref_hash_not_implemented (args ):
414
+ if sys .version_info .minor >= 6 :
415
+ raise SystemError
416
+ else :
417
+ raise TypeError
418
+
419
+ test_PyObject_HashNotImplemented = CPyExtFunction (
420
+ _ref_hash_not_implemented ,
421
+ lambda : (
422
+ ("foo" ,),
423
+ ),
424
+ arguments = ["PyObject* object" ],
425
+ argspec = "O" ,
426
+ resultspec = "i" ,
427
+ cmpfunc = unhandled_error_compare
428
+ )
400
429
__PyObject_GetAttr_ARGS = (
401
430
(MyObject (), "foo" ),
402
431
([], "__len__" ),
0 commit comments