Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions src/runtime/MethodBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,11 @@ static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStar
margs[paramIndex] = defaultArgList[paramIndex - pyArgCount];
}

if (parameter.ParameterType.IsByRef)
{
outs++;
}

continue;
}

Expand Down Expand Up @@ -817,6 +822,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;
Expand Down
28 changes: 4 additions & 24 deletions tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand All @@ -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
Expand All @@ -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."""
Expand Down