8000 allow Python not passing fake arguments for out parameters (#1672) · pythonnet/pythonnet@f69753c · GitHub
[go: up one dir, main page]

Skip to content

Commit f69753c

Browse files
authored
allow Python not passing fake arguments for out parameters (#1672)
1 parent 75f4398 commit f69753c

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@
8484
- ([@DanBarzilian](https://github.com/DanBarzilian))
8585
- ([@alxnull](https://github.com/alxnull))
8686
- ([@gpetrou](https://github.com/gpetrou))
87+
- Ehsan Iran-Nejad ([@eirannejad](https://github.com/eirannejad))

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Instead, `PyIterable` does that.
109109
- Empty parameter names (as can be generated from F#) do not cause crashes
110110
- Unicode strings with surrogates were truncated when converting from Python
111111
- `Reload` mode now supports generic methods (previously Python would stop seeing them after reload)
112+
- Temporarily fixed issue resolving method overload when method signature has `out` parameters ([#1672](i1672))
112113

113114
### Removed
114115

@@ -881,3 +882,4 @@ This version improves performance on benchmarks significantly compared to 2.3.
881882
[i1342]: https://github.com/pythonnet/pythonnet/issues/1342
882883
[i238]: https://github.com/pythonnet/pythonnet/issues/238
883884
[i1481]: https://github.com/pythonnet/pythonnet/issues/1481
885+
[i1672]: https://github.com/pythonnet/pythonnet/pull/1672

src/runtime/MethodBinder.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,11 @@ static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStar
632632
margs[paramIndex] = defaultArgList[paramIndex - pyArgCount];
633633
}
634634

635+
if (parameter.ParameterType.IsByRef)
636+
{
637+
outs++;
638+
}
639+
635640
continue;
636641
}
637642

@@ -817,6 +822,9 @@ static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] pa
817822
defaultArgList.Add(parameters[v].GetDefaultValue());
818823
defaultsNeeded++;
819824
}
825+
else if (parameters[v].IsOut) {
826+
defaultArgList.Add(null);
827+
}
820828
else if (!paramsArray)
821829
{
822830
match = false;

tests/test_method.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,16 @@ def test_string_out_params():
280280
assert result[1] == "output string"
281281

282282

283+
def test_string_out_params_without_passing_string_value():
284+
"""Test use of string out-parameters."""
285+
# @eirannejad 2022-01-13
286+
result = MethodTest.TestStringOutParams("hi")
287+
assert isinstance(result, tuple)
288+
assert len(result) == 2
289+
assert result[0] is True
290+
assert result[1] == "output string"
291+
292+
283293
def test_string_ref_params():
284294
"""Test use of string byref parameters."""
285295
result = MethodTest.TestStringRefParams("hi", "there")
@@ -308,6 +318,16 @@ def test_value_out_params():
308318
MethodTest.TestValueOutParams("hi", None)
309319

310320

321+
def test_value_out_params_without_passing_string_value():
322+
"""Test use of string out-parameters."""
323+
# @eirannejad 2022-01-13
324+
result = MethodTest.TestValueOutParams("hi")
325+
assert isinstance(result, tuple)
326+
assert len(result) == 2
327+
assert result[0] is True
328+
assert result[1] == 42
329+
330+
311331
def test_value_ref_params():
312332
"""Test use of value type byref parameters."""
313333
result = MethodTest.TestValueRefParams("hi", 1)
@@ -336,6 +356,15 @@ def test_object_out_params():
336356
assert isinstance(result[1], System.Exception)
337357

338358

359+
def test_object_out_params_without_passing_string_value():
360+
"""Test use of object out-parameters."""
361+
result = MethodTest.TestObjectOutParams("hi")
362+
assert isinstance(result, tuple)
363+
assert len(result) == 2
364+
assert result[0] is True
365+
assert isinstance(result[1], System.Exception)
366+
367+
339368
def test_object_ref_params():
340369
"""Test use of object byref parameters."""
341370
result = MethodTest.TestObjectRefParams("hi", MethodTest())
@@ -364,6 +393,15 @@ def test_struct_out_params():
364393
MethodTest.TestValueRefParams("hi", None)
365394

366395

396+
def test_struct_out_params_without_passing_string_value():
397+
"""Test use of struct out-parameters."""
398+
result = MethodTest.TestStructOutParams("hi")
399+
assert isinstance(result, tuple)
400+
assert len(result) == 2
401+
assert result[0] is True
402+
assert isinstance(result[1], System.Guid)
403+
404+
367405
def test_struct_ref_params():
368406
"""Test use of struct byref parameters."""
369407
result = MethodTest.TestStructRefParams("hi", System.Guid.NewGuid())

0 commit comments

Comments
 (0)
0