From a13d3c9d99171db6c207d6bb561e230bfebe9e00 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 13 Jan 2022 11:17:36 -0800 Subject: [PATCH 1/7] temp fixed method binder for out params --- src/runtime/MethodBinder.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/runtime/MethodBinder.cs b/src/runtime/MethodBinder.cs index 42d3822fc..eaac69dac 100644 --- a/src/runtime/MethodBinder.cs +++ b/src/runtime/MethodBinder.cs @@ -632,6 +632,9 @@ static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStar margs[paramIndex] = defaultArgList[paramIndex - pyArgCount]; } + if (parameter.ParameterType.IsByRef) + outs++; + continue; } @@ -817,6 +820,9 @@ static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] pa defaultArgList.Add(parameters[v].GetDefaultValue()); defaultsNeeded++; } + else if (parameters[v].IsOut) { + defaultArgList.Add(null); + } else if (!paramsArray) { match = false; From 21ea5f89b4768abd5d8b8dc12557cede16c0f266 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 13 Jan 2022 16:15:56 -0800 Subject: [PATCH 2/7] Fixed C# code styling --- src/runtime/MethodBinder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/runtime/MethodBinder.cs b/src/runtime/MethodBinder.cs index eaac69dac..8b9ee9c00 100644 --- a/src/runtime/MethodBinder.cs +++ b/src/runtime/MethodBinder.cs @@ -633,7 +633,9 @@ static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStar } if (parameter.ParameterType.IsByRef) + { outs++; + } continue; } From f61faa34a4697a71d57fe4b020628dd371037f69 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 13 Jan 2022 16:16:08 -0800 Subject: [PATCH 3/7] added contributer --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 912831836..92f1a4a97 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -84,3 +84,4 @@ - ([@DanBarzilian](https://github.com/DanBarzilian)) - ([@alxnull](https://github.com/alxnull)) - ([@gpetrou](https://github.com/gpetrou)) +- Ehsan Iran-Nejad ([@eirannejad](https://github.com/eirannejad)) From 6c5e56550fb7ee6da759cb2beed4575e2ebf86d9 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 13 Jan 2022 16:16:17 -0800 Subject: [PATCH 4/7] updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf64c3a64..60548ae10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,7 @@ Instead, `PyIterable` does that. - Empty parameter names (as can be generated from F#) do not cause crashes - Unicode strings with surrogates were truncated when converting from Python - `Reload` mode now supports generic methods (previously Python would stop seeing them after reload) +- Temporarily fixed issue resolving method overload when method signature has `out` parameters ([#1672](i1672)) ### Removed @@ -881,3 +882,4 @@ This version improves performance on benchmarks significantly compared to 2.3. [i1342]: https://github.com/pythonnet/pythonnet/issues/1342 [i238]: https://github.com/pythonnet/pythonnet/issues/238 [i1481]: https://github.com/pythonnet/pythonnet/issues/1481 +[i1672]: https://github.com/pythonnet/pythonnet/pull/1672 \ No newline at end of file From 1964a494ccc9b0bd7db2bef028ba0193cd7d969a Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 13 Jan 2022 17:23:04 -0800 Subject: [PATCH 5/7] modified existing method out parameter tests existing tests are passing bogus values to force matching the method signature these tests should pass with the recent method binder fix, without passing the bogus values --- tests/test_method.py | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/tests/test_method.py b/tests/test_method.py index e81652b54..b5a05b0cc 100644 --- a/tests/test_method.py +++ b/tests/test_method.py @@ -267,13 +267,7 @@ def test_params_method_with_lists(): def test_string_out_params(): """Test use of string out-parameters.""" - result = MethodTest.TestStringOutParams("hi", "there") - assert isinstance(result, tuple) - assert len(result) == 2 - assert result[0] is True - assert result[1] == "output string" - - result = MethodTest.TestStringOutParams("hi", None) + result = MethodTest.TestStringOutParams("hi") assert isinstance(result, tuple) assert len(result) == 2 assert result[0] is True @@ -297,16 +291,12 @@ def test_string_ref_params(): def test_value_out_params(): """Test use of value type out-parameters.""" - result = MethodTest.TestValueOutParams("hi", 1) + result = MethodTest.TestValueOutParams("hi") assert isinstance(result, tuple) assert len(result) == 2 assert result[0] is True assert result[1] == 42 - # None cannot be converted to a value type like int, long, etc. - with pytest.raises(TypeError): - MethodTest.TestValueOutParams("hi", None) - def test_value_ref_params(): """Test use of value type byref parameters.""" @@ -323,13 +313,7 @@ def test_value_ref_params(): def test_object_out_params(): """Test use of object out-parameters.""" - result = MethodTest.TestObjectOutParams("hi", MethodTest()) - assert isinstance(result, tuple) - assert len(result) == 2 - assert result[0] is True - assert isinstance(result[1], System.Exception) - - result = MethodTest.TestObjectOutParams("hi", None) + result = MethodTest.TestObjectOutParams("hi") assert isinstance(result, tuple) assert len(result) == 2 assert result[0] is True @@ -353,16 +337,12 @@ def test_object_ref_params(): def test_struct_out_params(): """Test use of struct out-parameters.""" - result = MethodTest.TestStructOutParams("hi", System.Guid.NewGuid()) + result = MethodTest.TestStructOutParams("hi") assert isinstance(result, tuple) assert len(result) == 2 assert result[0] is True assert isinstance(result[1], System.Guid) - # None cannot be converted to a value type like a struct - with pytest.raises(TypeError): - MethodTest.TestValueRefParams("hi", None) - def test_struct_ref_params(): """Test use of struct byref parameters.""" From f07cbb980c5760bb18438788be23007e5bc4a9e3 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 13 Jan 2022 17:42:18 -0800 Subject: [PATCH 6/7] Revert "modified existing method out parameter tests" This reverts commit 1964a494ccc9b0bd7db2bef028ba0193cd7d969a. --- tests/test_method.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/test_method.py b/tests/test_method.py index b5a05b0cc..e81652b54 100644 --- a/tests/test_method.py +++ b/tests/test_method.py @@ -267,7 +267,13 @@ def test_params_method_with_lists(): def test_string_out_params(): """Test use of string out-parameters.""" - result = MethodTest.TestStringOutParams("hi") + result = MethodTest.TestStringOutParams("hi", "there") + assert isinstance(result, tuple) + assert len(result) == 2 + assert result[0] is True + assert result[1] == "output string" + + result = MethodTest.TestStringOutParams("hi", None) assert isinstance(result, tuple) assert len(result) == 2 assert result[0] is True @@ -291,12 +297,16 @@ def test_string_ref_params(): def test_value_out_params(): """Test use of value type out-parameters.""" - result = MethodTest.TestValueOutParams("hi") + result = MethodTest.TestValueOutParams("hi", 1) assert isinstance(result, tuple) assert len(result) == 2 assert result[0] is True assert result[1] == 42 + # None cannot be converted to a value type like int, long, etc. + with pytest.raises(TypeError): + MethodTest.TestValueOutParams("hi", None) + def test_value_ref_params(): """Test use of value type byref parameters.""" @@ -313,7 +323,13 @@ def test_value_ref_params(): def test_object_out_params(): """Test use of object out-parameters.""" - result = MethodTest.TestObjectOutParams("hi") + result = MethodTest.TestObjectOutParams("hi", MethodTest()) + assert isinstance(result, tuple) + assert len(result) == 2 + assert result[0] is True + assert isinstance(result[1], System.Exception) + + result = MethodTest.TestObjectOutParams("hi", None) assert isinstance(result, tuple) assert len(result) == 2 assert result[0] is True @@ -337,12 +353,16 @@ def test_object_ref_params(): def test_struct_out_params(): """Test use of struct out-parameters.""" - result = MethodTest.TestStructOutParams("hi") + result = MethodTest.TestStructOutParams("hi", System.Guid.NewGuid()) assert isinstance(result, tuple) assert len(result) == 2 assert result[0] is True assert isinstance(result[1], System.Guid) + # None cannot be converted to a value type like a struct + with pytest.raises(TypeError): + MethodTest.TestValueRefParams("hi", None) + def test_struct_ref_params(): """Test use of struct byref parameters.""" From 961bd19e20cf1abdab8e7ba8a9a426308fe56b31 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 13 Jan 2022 17:53:55 -0800 Subject: [PATCH 7/7] now testing out-parameters w/o explicitly passing values --- tests/test_method.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_method.py b/tests/test_method.py index e81652b54..e2d8d5b06 100644 --- a/tests/test_method.py +++ b/tests/test_method.py @@ -280,6 +280,16 @@ def test_string_out_params(): assert result[1] == "output string" +def test_string_out_params_without_passing_string_value(): + """Test use of string out-parameters.""" + # @eirannejad 2022-01-13 + result = MethodTest.TestStringOutParams("hi") + assert isinstance(result, tuple) + assert len(result) == 2 + assert result[0] is True + assert result[1] == "output string" + + def test_string_ref_params(): """Test use of string byref parameters.""" result = MethodTest.TestStringRefParams("hi", "there") @@ -308,6 +318,16 @@ def test_value_out_params(): MethodTest.TestValueOutParams("hi", None) +def test_value_out_params_without_passing_string_value(): + """Test use of string out-parameters.""" + # @eirannejad 2022-01-13 + result = MethodTest.TestValueOutParams("hi") + assert isinstance(result, tuple) + assert len(result) == 2 + assert result[0] is True + assert result[1] == 42 + + def test_value_ref_params(): """Test use of value type byref parameters.""" result = MethodTest.TestValueRefParams("hi", 1) @@ -336,6 +356,15 @@ def test_object_out_params(): assert isinstance(result[1], System.Exception) +def test_object_out_params_without_passing_string_value(): + """Test use of object out-parameters.""" + result = MethodTest.TestObjectOutParams("hi") + assert isinstance(result, tuple) + assert len(result) == 2 + assert result[0] is True + assert isinstance(result[1], System.Exception) + + def test_object_ref_params(): """Test use of object byref parameters.""" result = MethodTest.TestObjectRefParams("hi", MethodTest()) @@ -364,6 +393,15 @@ def test_struct_out_params(): MethodTest.TestValueRefParams("hi", None) +def test_struct_out_params_without_passing_string_value(): + """Test use of struct out-parameters.""" + result = MethodTest.TestStructOutParams("hi") + assert isinstance(result, tuple) + assert len(result) == 2 + assert result[0] is True + assert isinstance(result[1], System.Guid) + + def test_struct_ref_params(): """Test use of struct byref parameters.""" result = MethodTest.TestStructRefParams("hi", System.Guid.NewGuid())