Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fixed ForbidPythonThreadsAttribute being ignored in certain scenarios#1815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
filmor merged 1 commit intopythonnet:masterfromlosttech:ForbidThreadsFix
Jun 13, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletionsrc/runtime/Types/MethodObject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,7 +27,7 @@ internal class MethodObject : ExtensionType
internal PyString? doc;
internal MaybeType type;

public MethodObject(MaybeType type, string name, MethodBase[] info, bool allow_threads = MethodBinder.DefaultAllowThreads)
public MethodObject(MaybeType type, string name, MethodBase[] info, bool allow_threads)
{
this.type = type;
this.name = name;
Expand All@@ -45,6 +45,11 @@ public MethodObject(MaybeType type, string name, MethodBase[] info, bool allow_t
binder.allow_threads = allow_threads;
}

public MethodObject(MaybeType type, string name, MethodBase[] info)
: this(type, name, info, allow_threads: AllowThreads(info))
{
}

public bool IsInstanceConstructor => name == "__init__";

public MethodObject WithOverloads(MethodBase[] overloads)
Expand DownExpand Up@@ -206,5 +211,27 @@ public static NewReference tp_repr(BorrowedReference ob)
var self = (MethodObject)GetManagedObject(ob)!;
return Runtime.PyString_FromString($"<method '{self.name}'>");
}

static bool AllowThreads(MethodBase[] methods)
{
bool hasAllowOverload = false, hasForbidOverload = false;
foreach (var method in methods)
{
bool forbidsThreads = method.GetCustomAttribute<ForbidPythonThreadsAttribute>(inherit: false) != null;
if (forbidsThreads)
{
hasForbidOverload = true;
}
else
{
hasAllowOverload = true;
}
}

if (hasAllowOverload && hasForbidOverload)
throw new NotImplementedException("All method overloads currently must either allow or forbid Python threads together");

return !hasForbidOverload;
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp