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

Proposal: Implement binding manager to hold binding overrides#2543

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

Open
koubaa wants to merge1 commit intopythonnet:master
base:master
Choose a base branch
Loading
fromkoubaa:add-binding-options-upstream
Open
Show file tree
Hide file tree
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
65 changes: 65 additions & 0 deletionssrc/runtime/BindingOptions.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Reflection;

namespace Python.Runtime
{
public class BindingOptions
{
private bool _SuppressDocs = false;
private bool _SuppressOverloads = false;

//[ModuleProperty]
public bool SuppressDocs
{
get { return _SuppressDocs; }
set { _SuppressDocs = value; }
}

//[ModuleProperty]
public bool SuppressOverloads
{
get { return _SuppressOverloads; }
set { _SuppressOverloads = value; }
}
}

public class BindingManager
{
static IDictionary<Type, BindingOptions> _typeOverrides = new Dictionary<Type, BindingOptions>();
static IDictionary<Assembly, BindingOptions> _assemblyOverrides = new Dictionary<Assembly, BindingOptions>();
static BindingOptions _defaultBindingOptions = new BindingOptions();

public static BindingOptions GetBindingOptions(Type type)
{
if (_typeOverrides.ContainsKey(type))
{
return _typeOverrides[type];
}

if (_assemblyOverrides.ContainsKey(type.Assembly))
{
return _assemblyOverrides[type.Assembly];
}
return _defaultBindingOptions;
}

public static BindingOptions DefaultBindingOptions => _defaultBindingOptions;

public static void SetBindingOptions(Type type, BindingOptions options)
{
_typeOverrides[type] = options;
}

public static void SetBindingOptions(Assembly assembly, BindingOptions options)
{
_assemblyOverrides[assembly] = options;
}

public static void Clear()
{
_typeOverrides.Clear();
_assemblyOverrides.Clear();
}
}
}
5 changes: 3 additions & 2 deletionssrc/runtime/ClassManager.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,6 +210,7 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p
// information, including generating the member descriptors
// that we'll be putting in the Python class __dict__.

var bindingOptions = BindingManager.GetBindingOptions(type);
ClassInfo info = GetClassInfo(type, impl);

impl.indexer = info.indexer;
Expand DownExpand Up@@ -254,7 +255,7 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p
if (co.NumCtors > 0 && !co.HasCustomNew())
{
// Implement Overloads on the class object
if (!CLRModule._SuppressOverloads)
if (!bindingOptions.SuppressOverloads)
{
// HACK: __init__ points to instance constructors.
// When unbound they fully instantiate object, so we get overloads for free from MethodBinding.
Expand All@@ -265,7 +266,7 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p
}

// don't generate the docstring if one was already set from a DocStringAttribute.
if (!CLRModule._SuppressDocs && doc.IsNull())
if (!bindingOptions.SuppressDocs && doc.IsNull())
{
doc = co.GetDocString();
Runtime.PyDict_SetItem(dict, PyIdentifier.__doc__, doc.Borrow());
Expand Down
13 changes: 4 additions & 9 deletionssrc/runtime/Types/ClrModule.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,6 @@ internal class CLRModule : ModuleObject
protected static bool interactive_preload = true;
internal static bool preload;
// XXX Test performance of new features //
internal static bool _SuppressDocs = false;
internal static bool _SuppressOverloads = false;

static CLRModule()
Expand All@@ -39,10 +38,6 @@ public static void Reset()
{
interactive_preload = true;
preload = false;

// XXX Test performance of new features //
_SuppressDocs = false;
_SuppressOverloads = false;
}

/// <summary>
Expand DownExpand Up@@ -82,15 +77,15 @@ public static void setPreload(bool preloadFlag)
//[ModuleProperty]
public static bool SuppressDocs
{
get { return_SuppressDocs; }
set {_SuppressDocs = value; }
get { returnBindingManager.DefaultBindingOptions.SuppressDocs; }
set {BindingManager.DefaultBindingOptions.SuppressDocs = value; }
}

//[ModuleProperty]
public static bool SuppressOverloads
{
get { return_SuppressOverloads; }
set {_SuppressOverloads = value; }
get { returnBindingManager.DefaultBindingOptions.SuppressOverloads; }
set {BindingManager.DefaultBindingOptions.SuppressOverloads = value; }
}

[ModuleFunction]
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp