Skip to content

Commit ba61f42

Browse files
author
Barton Cline
committed
Actually tests to see if a ClassObject has constructors and, if so, generates a __doc__ string.
Formerly, the __doc__ string was set to an empty string. Now it remains None and test_enum.py checks for that. This is also a step toward SomeObject.Overloads[]() handling which, of course, should not be attempted if the ClassObject doesn't have constructors. The current readme.html details the direction I'm heading with that one.
1 parent a9b0074 commit ba61f42

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

pythonnet/src/runtime/classmanager.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,14 @@ private static ClassBase CreateClass(Type type) {
129129
// If class has constructors, generate an __doc__ attribute.
130130

131131
ClassObject co = impl as ClassObject;
132+
// If this is a ClassObject AND it has constructors, generate a __doc__ attribute.
133+
// required that the ClassObject.ctors be changed to internal
132134
if (co != null) {
133-
IntPtr doc = co.GetDocString();
134-
Runtime.PyDict_SetItemString(dict, "__doc__", doc);
135-
Runtime.Decref(doc);
135+
if (co.ctors.Length > 0) {
136+
IntPtr doc = co.GetDocString();
137+
Runtime.PyDict_SetItemString(dict, "__doc__", doc);
138+
Runtime.Decref(doc);
139+
}
136140
}
137141

138142
return impl;

pythonnet/src/runtime/classobject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ namespace Python.Runtime {
2121

2222
internal class ClassObject : ClassBase {
2323

24-
ConstructorBinder binder;
25-
ConstructorInfo[] ctors;
24+
internal ConstructorBinder binder;
25+
internal ConstructorInfo[] ctors;
2626

2727
internal ClassObject(Type tp) : base(tp) {
2828
ctors = type.GetConstructors();

pythonnet/src/tests/test_enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def testEnumStandardAttrs(self):
2020
self.failUnless(DayOfWeek.__name__ == 'DayOfWeek')
2121
self.failUnless(DayOfWeek.__module__ == 'System')
2222
self.failUnless(type(DayOfWeek.__dict__) == types.DictProxyType)
23-
self.failUnless(DayOfWeek.__doc__ == '')
23+
self.failUnless(DayOfWeek.__doc__ == None)
2424

2525

2626
def testEnumGetMember(self):

0 commit comments

Comments
 (0)