@@ -1936,12 +1936,12 @@ pub const Set = extern struct {
19361936
19371937 // Return true if p is a set object or an instance of a subtype. This function always succeeds.
19381938 pub inline fn check (obj : * const Object ) bool {
1939- return c .PySet_Check (@as ([* c ]c .PyObject , @ptrCast (obj ))) != 0 ;
1939+ return c .PySet_Check (@as ([* c ]c .PyObject , @constCast ( @ ptrCast (obj )))) ;
19401940 }
19411941
19421942 // Return true if p is a set object but not an instance of a subtype. This function always succeeds.
19431943 pub inline fn checkExact (obj : * const Object ) bool {
1944- return c .PySet_CheckExact (@as ([* c ]c .PyObject , @ptrCast (obj ))) != 0 ;
1944+ return c .PySet_CheckExact (@as ([* c ]c .PyObject , @constCast ( @ ptrCast (obj ) ))) != 0 ;
19451945 }
19461946
19471947 // Return a new set containing objects returned by the iterable.
@@ -1978,6 +1978,11 @@ pub const Set = extern struct {
19781978 return @ptrCast (c .PyFrozenSet_New (@ptrCast (iterable )));
19791979 }
19801980
1981+ // Create a copy of this set
1982+ pub fn copy (self : * Set ) ! * Set {
1983+ return try new (@ptrCast (self ));
1984+ }
1985+
19811986 // Get the size and check for errors.
19821987 pub inline fn size (self : * Set ) ! usize {
19831988 const r = self .sizeUnchecked ();
@@ -2081,7 +2086,7 @@ pub const Code = extern struct {
20812086
20822087 // Return true if co is a code object. This function always succeeds.
20832088 pub fn check (obj : * const Object ) bool {
2084- return c .PyCode_Check (@constCast (@ptrCast (obj ))) != 0 ;
2089+ return c .PyCode_Check (@as ([ * c ] c . PyObject , @ constCast (@ptrCast (obj ) ))) != 0 ;
20852090 }
20862091};
20872092
@@ -2094,12 +2099,12 @@ pub const Function = extern struct {
20942099 // Return true if o is a function object (has type PyFunction_Type).
20952100 // The parameter must not be NULL. This function always succeeds.
20962101 pub fn check (obj : * const Object ) bool {
2097- return c .PyFunction_Check (@constCast (@ptrCast (obj ))) != 0 ;
2102+ return c .PyFunction_Check (@as ([ * c ] c . PyObject , @ constCast (@ptrCast (obj ) ))) != 0 ;
20982103 }
20992104
21002105 // Return a new function object associated with the code object code.
21012106 // globals must be a dictionary with the global variables accessible to the function.
2102- pub fn new (code : * Code , globals : * Dict ) ! Function {
2107+ pub fn new (code : * Code , globals : * Dict ) ! * Function {
21032108 if (newUnchecked (code , globals )) | f | {
21042109 return @ptrCast (f );
21052110 }
@@ -2135,7 +2140,7 @@ pub const Function = extern struct {
21352140 if (c .PyFunction_GetModule (@ptrCast (self ))) | r | {
21362141 return @ptrCast (r );
21372142 }
2138- return @ptrCast (checkErrorOccurred ());
2143+ return @ptrCast (try checkErrorOccurred ());
21392144 }
21402145
21412146 // Return the argument default values of the function object op.
@@ -2145,7 +2150,7 @@ pub const Function = extern struct {
21452150 if (c .PyFunction_GetDefaults (@ptrCast (self ))) | r | {
21462151 return @ptrCast (r );
21472152 }
2148- return @ptrCast (checkErrorOccurred ());
2153+ return @ptrCast (try checkErrorOccurred ());
21492154 }
21502155
21512156 // Set the argument default values for the function object op.
@@ -2162,7 +2167,7 @@ pub const Function = extern struct {
21622167 if (c .PyFunction_GetClosure (@ptrCast (self ))) | r | {
21632168 return @ptrCast (r );
21642169 }
2165- return @ptrCast (checkErrorOccurred ());
2170+ return @ptrCast (try checkErrorOccurred ());
21662171 }
21672172
21682173 // Set the closure associated with the function object op.
@@ -2179,7 +2184,7 @@ pub const Function = extern struct {
21792184 if (c .PyFunction_GetAnnotations (@ptrCast (self ))) | r | {
21802185 return @ptrCast (r );
21812186 }
2182- return @ptrCast (checkErrorOccurred ());
2187+ return @ptrCast (try checkErrorOccurred ());
21832188 }
21842189
21852190 // Set the annotations for the function object op.
@@ -2200,14 +2205,14 @@ pub const Method = extern struct {
22002205 // Return true if o is a method object (has type PyMethod_Type).
22012206 // The parameter must not be NULL. This function always succeeds.
22022207 pub fn check (obj : * Object ) bool {
2203- return c .PyMethod_Check (@constCast (@ptrCast (obj ))) != 0 ;
2208+ return c .PyMethod_Check (@as ([ * c ] c . PyObject , @ constCast (@ptrCast (obj ) ))) != 0 ;
22042209 }
22052210
22062211 // Return a new method object, with func being any callable object and self the
22072212 // instance the method should be bound. func is the function that will be called
22082213 // when the method is called. self must not be NULL.
22092214 // Returns new reference
2210- pub fn new (func : * Function , obj : * Object ) ! Method {
2215+ pub fn new (func : * Function , obj : * Object ) ! * Method {
22112216 if (newUnchecked (func , obj )) | f | {
22122217 return @ptrCast (f );
22132218 }
@@ -2363,5 +2368,11 @@ var global_allocator = Allocator{};
23632368pub const allocator = global_allocator .allocator ();
23642369
23652370test "all" {
2371+ @setEvalBranchQuota (10000 );
23662372 std .testing .refAllDecls (@This ());
2373+ // refAllDeclsRecursive(@This()) doesn't work due to a problem
2374+ // with translating the bitfield in PyUnicodeObject
2375+ inline for (.{ Object , Type , Metaclass , Bool , Int , Float , Str , Bytes , Tuple , List , Dict , Set , Code , Function , Method , Module , Allocator }) | T | {
2376+ std .testing .refAllDeclsRecursive (T );
2377+ }
23672378}
0 commit comments