Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Support to Named Arguments #41

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.5.29
current_version = 1.0.5.30
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
{major}.{minor}.{patch}.{release}{dev}
Expand Down
2 changes: 2 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
-   Ivan Cronyn ([@cronan](https://github.com/cronan))
-   Jeff Reback ([@jreback](https://github.com/jreback))
- Joe Frayne ([@jfrayne](https://github.com/jfrayne))
- Joe Lidbetter ([@jmlidbetter](https://github.com/jmlidbetter))
- Joe Savage ([@s4v4g3](https://github.com/s4v4g3))
- John Burnett ([@johnburnett](https://github.com/johnburnett))
- John Wilkes ([@jbw3](https://github.com/jbw3))
- Luke Stratman ([@lstratman](https://github.com/lstratman))
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
## [unreleased][]

### Added

- Added automatic NuGet package generation in appveyor and local builds

### Changed

- Added argument types information to "No method matches given arguments" message
- Moved wheel import in setup.py inside of a try/except to prevent pip collection failures
- Removes PyLong_GetMax and PyClass_New when targetting Python3
- Added support for converting python iterators to C# arrays
- Changed usage of obselete function GetDelegateForFunctionPointer(IntPtr, Type) to GetDelegateForFunctionPointer<TDelegate>(IntPtr)
- Added support for kwarg parameters when calling .NET methods from Python

### Fixed

- Fixed runtime that fails loading when using pythonnet in an environment
together with Nuitka
- Fixes bug where delegates get casts (dotnetcore)

## [2.4.0][]

### Added

- Added support for embedding python into dotnet core 2.0 (NetStandard 2.0)
- Added new build system (pythonnet.15.sln) based on dotnetcore-sdk/xplat(crossplatform msbuild).
Currently there two side-by-side build systems that produces the same output (net40) from the same sources.
Expand Down
2 changes: 1 addition & 1 deletion conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: pythonnet
version: "1.0.5.29"
version: "1.0.5.30"

build:
skip: True # [not win]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def run(self):

setup(
name="pythonnet",
version="1.0.5.29",
version="1.0.5.30",
description=".Net and Mono integration for Python",
url='https://pythonnet.github.io/',
license='MIT',
Expand Down
2 changes: 1 addition & 1 deletion src/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
// Version Information. Keeping it simple. May need to revisit for Nuget
// See: https://codingforsmarties.wordpress.com/2016/01/21/how-to-version-assemblies-destined-for-nuget/
// AssemblyVersion can only be numeric
[assembly: AssemblyVersion("1.0.5.29")]
[assembly: AssemblyVersion("1.0.5.30")]
2 changes: 1 addition & 1 deletion src/clrmodule/ClrModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void initclr()
{
#if USE_PYTHON_RUNTIME_VERSION
// Has no effect until SNK works. Keep updated anyways.
Version = new Version("1.0.5.29"),
Version = new Version("1.0.5.30"),
#endif
CultureInfo = CultureInfo.InvariantCulture
};
Expand Down
600 changes: 377 additions & 223 deletions src/runtime/methodbinder.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/runtime/resources/clr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Code in this module gets loaded into the main clr module.
"""

__version__ = "1.0.5.29"
__version__ = "1.0.5.30"


class clrproperty(object):
Expand Down
33 changes: 33 additions & 0 deletions src/testing/methodtest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Python.Test
{
Expand Down Expand Up @@ -651,6 +652,38 @@ public static string Casesensitive()
{
return "Casesensitive";
}

public static string DefaultParams(int a=0, int b=0, int c=0, int d=0)
{
return string.Format("{0}{1}{2}{3}", a, b, c, d);
}

public static string OptionalParams([Optional]int a, [Optional]int b, [Optional]int c, [Optional] int d)
{
return string.Format("{0}{1}{2}{3}", a, b, c, d);
}

public static bool OptionalParams_TestMissing([Optional]object a)
{
return a == Type.Missing;
}

public static bool OptionalParams_TestReferenceType([Optional]string a)
{
return a == null;
}

public static string OptionalAndDefaultParams([Optional]int a, [Optional]int b, int c=0, int d=0)
{
return string.Format("{0}{1}{2}{3}", a, b, c, d);
}

public static string OptionalAndDefaultParams2([Optional]int a, [Optional]int b, [Optional, DefaultParameterValue(1)]int c, int d = 2)
{
return string.Format("{0}{1}{2}{3}", a, b, c, d);
}


}


Expand Down
162 changes: 162 additions & 0 deletions src/tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ def test_no_object_in_param():

res = MethodTest.TestOverloadedNoObject(5)
assert res == "Got int"

res = MethodTest.TestOverloadedNoObject(i=7)
assert res == "Got int"

with pytest.raises(TypeError):
MethodTest.TestOverloadedNoObject("test")
Expand All @@ -787,9 +790,15 @@ def test_object_in_param():

res = MethodTest.TestOverloadedObject(5)
assert res == "Got int"

res = MethodTest.TestOverloadedObject(i=7)
assert res == "Got int"

res = MethodTest.TestOverloadedObject("test")
assert res == "Got object"

res = MethodTest.TestOverloadedObject(o="test")
assert res == "Got object"


def test_object_in_multiparam():
Expand All @@ -813,6 +822,42 @@ def test_object_in_multiparam():
res = MethodTest.TestOverloadedObjectTwo(7.24, 7.24)
assert res == "Got object-object"

res = MethodTest.TestOverloadedObjectTwo(a=5, b=5)
assert res == "Got int-int"

res = MethodTest.TestOverloadedObjectTwo(5, b=5)
assert res == "Got int-int"

res = MethodTest.TestOverloadedObjectTwo(a=5, b="foo")
assert res == "Got int-string"

res = MethodTest.TestOverloadedObjectTwo(5, b="foo")
assert res == "Got int-string"

res = MethodTest.TestOverloadedObjectTwo(a="foo", b=7.24)
assert res == "Got string-object"

res = MethodTest.TestOverloadedObjectTwo("foo", b=7.24)
assert res == "Got string-object"

res = MethodTest.TestOverloadedObjectTwo(a="foo", b="bar")
assert res == "Got string-string"

res = MethodTest.TestOverloadedObjectTwo("foo", b="bar")
assert res == "Got string-string"

res = MethodTest.TestOverloadedObjectTwo(a="foo", b=5)
assert res == "Got string-int"

res = MethodTest.TestOverloadedObjectTwo("foo", b=5)
assert res == "Got string-int"

res = MethodTest.TestOverloadedObjectTwo(a=7.24, b=7.24)
assert res == "Got object-object"

res = MethodTest.TestOverloadedObjectTwo(7.24, b=7.24)
assert res == "Got object-object"


def test_object_in_multiparam_exception():
"""Test method with object multiparams behaves"""
Expand Down Expand Up @@ -966,3 +1011,120 @@ def test_getting_overloaded_constructor_binding_does_not_leak_ref_count():
# simple test
refCount = sys.getrefcount(PlainOldClass.Overloads[int])
assert refCount == 1


def test_default_params():
# all positional parameters
res = MethodTest.DefaultParams(1,2,3,4)
assert res == "1234"

res = MethodTest.DefaultParams(1, 2, 3)
assert res == "1230"

res = MethodTest.DefaultParams(1, 2)
assert res == "1200"

res = MethodTest.DefaultParams(1)
assert res == "1000"

res = MethodTest.DefaultParams(a=2)
assert res == "2000"

res = MethodTest.DefaultParams(b=3)
assert res == "0300"

res = MethodTest.DefaultParams(c=4)
assert res == "0040"

res = MethodTest.DefaultParams(d=7)
assert res == "0007"

res = MethodTest.DefaultParams(a=2, c=5)
assert res == "2050"

res = MethodTest.DefaultParams(1, d=7, c=3)
assert res == "1037"

with pytest.raises(TypeError):
MethodTest.DefaultParams(1,2,3,4,5)

def test_optional_params():
res = MethodTest.OptionalParams(1, 2, 3, 4)
assert res == "1234"

res = MethodTest.OptionalParams(1, 2, 3)
assert res == "1230"

res = MethodTest.OptionalParams(1, 2)
assert res == "1200"

res = MethodTest.OptionalParams(1)
assert res == "1000"

res = MethodTest.OptionalParams(a=2)
assert res == "2000"

res = MethodTest.OptionalParams(b=3)
assert res == "0300"

res = MethodTest.OptionalParams(c=4)
assert res == "0040"

res = MethodTest.OptionalParams(d=7)
assert res == "0007"

res = MethodTest.OptionalParams(a=2, c=5)
assert res == "2050"

res = MethodTest.OptionalParams(1, d=7, c=3)
assert res == "1037"

res = MethodTest.OptionalParams_TestMissing()
assert res == True

res = MethodTest.OptionalParams_TestMissing(None)
assert res == False

res = MethodTest.OptionalParams_TestMissing(a = None)
assert res == False

res = MethodTest.OptionalParams_TestMissing(a='hi')
assert res == False

res = MethodTest.OptionalParams_TestReferenceType()
assert res == True

res = MethodTest.OptionalParams_TestReferenceType(None)
assert res == True

res = MethodTest.OptionalParams_TestReferenceType(a=None)
assert res == True

res = MethodTest.OptionalParams_TestReferenceType('hi')
assert res == False

res = MethodTest.OptionalParams_TestReferenceType(a='hi')
assert res == False

def test_optional_and_default_params():

res = MethodTest.OptionalAndDefaultParams()
assert res == "0000"

res = MethodTest.OptionalAndDefaultParams(1)
assert res == "1000"

res = MethodTest.OptionalAndDefaultParams(1, c=4)
assert res == "1040"

res = MethodTest.OptionalAndDefaultParams(b=4, c=7)
assert res == "0470"

res = MethodTest.OptionalAndDefaultParams2()
assert res == "0012"

res = MethodTest.OptionalAndDefaultParams2(a=1,b=2,c=3,d=4)
assert res == "1234"

res = MethodTest.OptionalAndDefaultParams2(b=2, c=3)
assert res == "0232"