Skip to content

Commit a157fb4

Browse files
committed
added regression test for #1427
(stack overflow trying to pass `System.Type` to `CanEncode`)
1 parent 6379221 commit a157fb4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/embed_tests/Codecs.cs

+25
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,31 @@ public void IterableDecoderTest()
296296
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out intEnumerable); });
297297
CollectionAssert.AreEqual(intEnumerable, new List<object> { 1, 2, 3 });
298298
}
299+
300+
// regression for https://github.com/pythonnet/pythonnet/issues/1427
301+
[Test]
302+
public void PythonRegisteredDecoder_NoStackOverflowOnSystemType()
303+
{
304+
const string PyCode = @"
305+
import clr
306+
import System
307+
from Python.Runtime import PyObjectConversions
308+
from Python.Runtime.Codecs import RawProxyEncoder
309+
310+
311+
class ListAsRawEncoder(RawProxyEncoder):
312+
__namespace__ = 'Dummy'
313+
def CanEncode(self, clr_type):
314+
return clr_type.Name == 'IList`1' and clr_type.Namespace == 'System.Collections.Generic'
315+
316+
317+
list_encoder = ListAsRawEncoder()
318+
PyObjectConversions.RegisterEncoder(list_encoder)
319+
320+
system_type = list_encoder.GetType()";
321+
322+
PythonEngine.Exec(PyCode);
323+
}
299324
}
300325

301326
/// <summary>

0 commit comments

Comments
 (0)