@@ -27,7 +27,7 @@ internal class MethodObject : ExtensionType
27
27
internal PyString ? doc ;
28
28
internal MaybeType type ;
29
29
30
- public MethodObject ( MaybeType type , string name , MethodBase [ ] info , bool allow_threads = MethodBinder . DefaultAllowThreads )
30
+ public MethodObject ( MaybeType type , string name , MethodBase [ ] info , bool allow_threads )
31
31
{
32
32
this . type = type ;
33
33
this . name = name ;
@@ -45,6 +45,11 @@ public MethodObject(MaybeType type, string name, MethodBase[] info, bool allow_t
45
45
binder . allow_threads = allow_threads ;
46
46
}
47
47
48
+ public MethodObject ( MaybeType type , string name , MethodBase [ ] info )
49
+ : this ( type , name , info , allow_threads : AllowThreads ( info ) )
50
+ {
51
+ }
52
+
48
53
public bool IsInstanceConstructor => name == "__init__" ;
49
54
50
55
public MethodObject WithOverloads ( MethodBase [ ] overloads )
@@ -206,5 +211,27 @@ public static NewReference tp_repr(BorrowedReference ob)
206
211
var self = ( MethodObject ) GetManagedObject ( ob ) ! ;
207
212
return Runtime . PyString_FromString ( $ "<method '{ self . name } '>") ;
208
213
}
214
+
215
+ static bool AllowThreads ( MethodBase [ ] methods )
216
+ {
217
+ bool hasAllowOverload = false , hasForbidOverload = false ;
218
+ foreach ( var method in methods )
219
+ {
220
+ bool forbidsThreads = method . GetCustomAttribute < ForbidPythonThreadsAttribute > ( inherit : false ) != null ;
221
+ if ( forbidsThreads )
222
+ {
223
+ hasForbidOverload = true ;
224
+ }
225
+ else
226
+ {
227
+ hasAllowOverload = true ;
228
+ }
229
+ }
230
+
231
+ if ( hasAllowOverload && hasForbidOverload )
232
+ throw new NotImplementedException ( "All method overloads currently must either allow or forbid Python threads together" ) ;
233
+
234
+ return ! hasForbidOverload ;
235
+ }
209
236
}
210
237
}
0 commit comments