| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b393ee5 commit 015a679
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -131,6 +131,20 @@ private static ClassBase CreateClass(Type type) { | |||
| 131 | 131 | } | |
| 132 | 132 | ||
| 133 | 133 | // If class has constructors, generate an __doc__ attribute. | |
| 134 | + | ||
| 135 | + IntPtr doc; | ||
| 136 | + Type marker = typeof(DocStringAttribute); | ||
| 137 | + Attribute[] attrs = (Attribute[])type.GetCustomAttributes(marker, false); | ||
| 138 | + if (attrs.Length == 0) { | ||
| 139 | + doc = IntPtr.Zero; | ||
| 140 | + } | ||
| 141 | + else { | ||
| 142 | + DocStringAttribute attr = (DocStringAttribute)attrs[0]; | ||
| 143 | + string docStr = attr.DocString; | ||
| 144 | + doc = Runtime.PyString_FromString(docStr); | ||
| 145 | + Runtime.PyDict_SetItemString(dict, "__doc__", doc); | ||
| 146 | + Runtime.Decref(doc); | ||
| 147 | + } | ||
| 134 | 148 | ||
| 135 | 149 | ClassObject co = impl as ClassObject; | |
| 136 | 150 | // If this is a ClassObject AND it has constructors, generate a __doc__ attribute. | |
@@ -143,12 +157,14 @@ private static ClassBase CreateClass(Type type) { | |||
| 143 | 157 | // XXX deprecate __overloads__ soon... | |
| 144 | 158 | Runtime.PyDict_SetItemString(dict, "__overloads__", ctors.pyHandle); | |
| 145 | 159 | Runtime.PyDict_SetItemString(dict, "Overloads", ctors.pyHandle); | |
| 146 | - | ||
| 147 | - IntPtr doc = co.GetDocString(); | ||
| 148 | - Runtime.PyDict_SetItemString(dict, "__doc__", doc); | ||
| 149 | - Runtime.Decref(doc); | ||
| 150 | - } | ||
| 151 | - } | ||
| 160 | + | ||
| 161 | + if (doc == IntPtr.Zero) { | ||
| 162 | + doc = co.GetDocString(); | ||
| 163 | + Runtime.PyDict_SetItemString(dict, "__doc__", doc); | ||
| 164 | + Runtime.Decref(doc); | ||
| 165 | + } | ||
| 166 | + } | ||
| 167 | + } | ||
| 152 | 168 | ||
| 153 | 169 | return impl; | |
| 154 | 170 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ namespace Python.Runtime { | |||
| 22 | 22 | //======================================================================= | |
| 23 | 23 | ||
| 24 | 24 | [Serializable()] | |
| 25 | - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate | AttributeTargets.Property)] | ||
| 25 | + [AttributeUsage(AttributeTargets.All)] | ||
| 26 | 26 | public class DocStringAttribute : Attribute { | |
| 27 | 27 | public DocStringAttribute(string docStr) { | |
| 28 | 28 | DocString = docStr; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,13 +71,21 @@ internal IntPtr GetDocString() { | |||
| 71 | 71 | if (doc != IntPtr.Zero) { | |
| 72 | 72 | return doc; | |
| 73 | 73 | } | |
| 74 | - MethodBase[] methods = binder.GetMethods(); | ||
| 75 | 74 | string str = ""; | |
| 76 | - for (int i = 0; i < methods.Length; i++) { | ||
| 75 | + Type marker = typeof(DocStringAttribute); | ||
| 76 | + MethodBase[] methods = binder.GetMethods(); | ||
| 77 | + foreach (MethodBase method in methods) { | ||
| 77 | 78 | if (str.Length > 0) | |
| 78 | 79 | str += Environment.NewLine; | |
| 79 | - str += methods[i].ToString(); | ||
| 80 | - } | ||
| 80 | + Attribute[] attrs = (Attribute[]) method.GetCustomAttributes(marker, false); | ||
| 81 | + if (attrs.Length == 0) { | ||
| 82 | + str += method.ToString(); | ||
| 83 | + } | ||
| 84 | + else { | ||
| 85 | + DocStringAttribute attr = (DocStringAttribute)attrs[0]; | ||
| 86 | + str += attr.DocString; | ||
| 87 | + } | ||
| 88 | + } | ||
| 81 | 89 | doc = Runtime.PyString_FromString(str); | |
| 82 | 90 | return doc; | |
| 83 | 91 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments