| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dfd746b commit 0295dd2
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,65 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Reflection; | ||
| 4 | + | ||
| 5 | + namespace Python.Runtime | ||
| 6 | + { | ||
| 7 | + public class BindingOptions | ||
| 8 | + { | ||
| 9 | + private bool _SuppressDocs = false; | ||
| 10 | + private bool _SuppressOverloads = false; | ||
| 11 | + | ||
| 12 | + //[ModuleProperty] | ||
| 13 | + public bool SuppressDocs | ||
| 14 | + { | ||
| 15 | + get { return _SuppressDocs; } | ||
| 16 | + set { _SuppressDocs = value; } | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + //[ModuleProperty] | ||
| 20 | + public bool SuppressOverloads | ||
| 21 | + { | ||
| 22 | + get { return _SuppressOverloads; } | ||
| 23 | + set { _SuppressOverloads = value; } | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public class BindingManager | ||
| 28 | + { | ||
| 29 | + static IDictionary<Type, BindingOptions> _typeOverrides = new Dictionary<Type, BindingOptions>(); | ||
| 30 | + static IDictionary<Assembly, BindingOptions> _assemblyOverrides = new Dictionary<Assembly, BindingOptions>(); | ||
| 31 | + static BindingOptions _defaultBindingOptions = new BindingOptions(); | ||
| 32 | + | ||
| 33 | + public static BindingOptions GetBindingOptions(Type type) | ||
| 34 | + { | ||
| 35 | + if (_typeOverrides.ContainsKey(type)) | ||
| 36 | + { | ||
| 37 | + return _typeOverrides[type]; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + if (_assemblyOverrides.ContainsKey(type.Assembly)) | ||
| 41 | + { | ||
| 42 | + return _assemblyOverrides[type.Assembly]; | ||
| 43 | + } | ||
| 44 | + return _defaultBindingOptions; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public static BindingOptions DefaultBindingOptions => _defaultBindingOptions; | ||
| 48 | + | ||
| 49 | + public static void SetBindingOptions(Type type, BindingOptions options) | ||
| 50 | + { | ||
| 51 | + _typeOverrides[type] = options; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public static void SetBindingOptions(Assembly assembly, BindingOptions options) | ||
| 55 | + { | ||
| 56 | + _assemblyOverrides[assembly] = options; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public static void Clear() | ||
| 60 | + { | ||
| 61 | + _typeOverrides.Clear(); | ||
| 62 | + _assemblyOverrides.Clear(); | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -210,6 +210,7 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p | |||
| 210 | 210 | // information, including generating the member descriptors | |
| 211 | 211 | // that we'll be putting in the Python class __dict__. | |
| 212 | 212 | ||
| 213 | + var bindingOptions = BindingManager.GetBindingOptions(type); | ||
| 213 | 214 | ClassInfo info = GetClassInfo(type, impl); | |
| 214 | 215 | ||
| 215 | 216 | impl.indexer = info.indexer; | |
@@ -254,7 +255,7 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p | |||
| 254 | 255 | if (co.NumCtors > 0 && !co.HasCustomNew()) | |
| 255 | 256 | { | |
| 256 | 257 | // Implement Overloads on the class object | |
| 257 | - if (!CLRModule._SuppressOverloads) | ||
| 258 | + if (!bindingOptions.SuppressOverloads) | ||
| 258 | 259 | { | |
| 259 | 260 | // HACK: __init__ points to instance constructors. | |
| 260 | 261 | // When unbound they fully instantiate object, so we get overloads for free from MethodBinding. | |
@@ -265,7 +266,7 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p | |||
| 265 | 266 | } | |
| 266 | 267 | ||
| 267 | 268 | // don't generate the docstring if one was already set from a DocStringAttribute. | |
| 268 | - if (!CLRModule._SuppressDocs && doc.IsNull()) | ||
| 269 | + if (!bindingOptions.SuppressDocs && doc.IsNull()) | ||
| 269 | 270 | { | |
| 270 | 271 | doc = co.GetDocString(); | |
| 271 | 272 | Runtime.PyDict_SetItem(dict, PyIdentifier.__doc__, doc.Borrow()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,6 @@ internal class CLRModule : ModuleObject | |||
| 16 | 16 | protected static bool interactive_preload = true; | |
| 17 | 17 | internal static bool preload; | |
| 18 | 18 | // XXX Test performance of new features // | |
| 19 | - internal static bool _SuppressDocs = false; | ||
| 20 | 19 | internal static bool _SuppressOverloads = false; | |
| 21 | 20 | ||
| 22 | 21 | static CLRModule() | |
@@ -39,10 +38,6 @@ public static void Reset() | |||
| 39 | 38 | { | |
| 40 | 39 | interactive_preload = true; | |
| 41 | 40 | preload = false; | |
| 42 | - | ||
| 43 | - // XXX Test performance of new features // | ||
| 44 | - _SuppressDocs = false; | ||
| 45 | - _SuppressOverloads = false; | ||
| 46 | 41 | } | |
| 47 | 42 | ||
| 48 | 43 | /// <summary> | |
@@ -82,15 +77,15 @@ public static void setPreload(bool preloadFlag) | |||
| 82 | 77 | //[ModuleProperty] | |
| 83 | 78 | public static bool SuppressDocs | |
| 84 | 79 | { | |
| 85 | - get { return _SuppressDocs; } | ||
| 86 | - set { _SuppressDocs = value; } | ||
| 80 | + get { return BindingManager.DefaultBindingOptions.SuppressDocs; } | ||
| 81 | + set { BindingManager.DefaultBindingOptions.SuppressDocs = value; } | ||
| 87 | 82 | } | |
| 88 | 83 | ||
| 89 | 84 | //[ModuleProperty] | |
| 90 | 85 | public static bool SuppressOverloads | |
| 91 | 86 | { | |
| 92 | - get { return _SuppressOverloads; } | ||
| 93 | - set { _SuppressOverloads = value; } | ||
| 87 | + get { return BindingManager.DefaultBindingOptions.SuppressOverloads; } | ||
| 88 | + set { BindingManager.DefaultBindingOptions.SuppressOverloads = value; } | ||
| 94 | 89 | } | |
| 95 | 90 | ||
| 96 | 91 | [ModuleFunction] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments