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

Commitc18db8c

Browse files
committed
Fix missing docstring for types with custom constructors
1 parent60a719c commitc18db8c

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

‎src/runtime/ClassManager.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ internal static ClassManagerState SaveRuntimeData()
8787
if((Runtime.PyDict_DelItemString(dict.Borrow(),member)==-1)&&
8888
(Exceptions.ExceptionMatches(Exceptions.KeyError)))
8989
{
90-
// Trying to remove a key that's not in the dictionary
90+
// Trying to remove a key that's not in the dictionary
9191
// raises an error. We don't care about it.
9292
Runtime.PyErr_Clear();
9393
}
@@ -215,7 +215,7 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p
215215
impl.indexer=info.indexer;
216216
impl.richcompare.Clear();
217217

218-
218+
219219
// Finally, initialize the class __dict__ and return the object.
220220
usingvarnewDict=Runtime.PyObject_GenericGetDict(pyType.Reference);
221221
BorrowedReferencedict=newDict.Borrow();
@@ -271,6 +271,15 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p
271271
Runtime.PyDict_SetItem(dict,PyIdentifier.__doc__,doc.Borrow());
272272
}
273273
}
274+
275+
if(Runtime.PySequence_Contains(dict,PyIdentifier.__doc__)!=1)
276+
{
277+
// Ensure that at least some doc string is set
278+
usingvarfallbackDoc=Runtime.PyString_FromString(
279+
$"Python wrapper for .NET type{type}"
280+
);
281+
Runtime.PyDict_SetItem(dict,PyIdentifier.__doc__,fallbackDoc.Borrow());
282+
}
274283
}
275284
doc.Dispose();
276285

@@ -562,7 +571,7 @@ private static ClassInfo GetClassInfo(Type type, ClassBase impl)
562571

563572
returnci;
564573
}
565-
574+
566575
/// <summary>
567576
/// This class owns references to PyObjects in the `members` member.
568577
/// The caller has responsibility to DECREF them.

‎tests/test_docstring.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ def test_doc_without_ctor():
2525
assertDocWithoutCtorTest.__doc__=='DocWithoutCtorTest Class'
2626
assertDocWithoutCtorTest.TestMethod.__doc__=='DocWithoutCtorTest TestMethod'
2727
assertDocWithoutCtorTest.StaticTestMethod.__doc__=='DocWithoutCtorTest StaticTestMethod'
28+
29+
30+
deftest_doc_primitve():
31+
fromSystemimportInt64,String
32+
33+
assertInt64.__doc__isnotNone
34+
assertString.__doc__isnotNone

‎tests/test_enum.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def test_enum_standard_attrs():
1515
assertDayOfWeek.__name__=='DayOfWeek'
1616
assertDayOfWeek.__module__=='System'
1717
assertisinstance(DayOfWeek.__dict__,DictProxyType)
18-
assertDayOfWeek.__doc__isNone
1918

2019

2120
deftest_enum_get_member():
@@ -139,7 +138,7 @@ def test_enum_undefined_value():
139138
# This should fail because our test enum doesn't have it.
140139
withpytest.raises(ValueError):
141140
Test.FieldTest().EnumField=Test.ShortEnum(20)
142-
141+
143142
# explicitly permit undefined values
144143
Test.FieldTest().EnumField=Test.ShortEnum(20,True)
145144

@@ -157,6 +156,6 @@ def test_enum_conversion():
157156

158157
withpytest.raises(TypeError):
159158
Test.FieldTest().EnumField="str"
160-
159+
161160
withpytest.raises(TypeError):
162161
Test.FieldTest().EnumField=1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp