Skip to content

Commit 41ac665

Browse files
committed
Merge remote-tracking branch 'remotes/upstream/master' into drop-dlopen
2 parents b7715ee + df0574d commit 41ac665

11 files changed

+365
-43
lines changed

.travis.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dist: trusty
1+
dist: xenial
22
sudo: false
33
language: python
44

@@ -12,16 +12,16 @@ matrix:
1212
addons: &xplat-addons
1313
apt:
1414
sources:
15-
- sourceline: deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main
15+
- sourceline: deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main
1616
key_url: https://packages.microsoft.com/keys/microsoft.asc
17-
- sourceline: deb http://download.mono-project.com/repo/ubuntu trusty main
17+
- sourceline: deb http://download.mono-project.com/repo/ubuntu xenial main
1818
key_url: http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xA6A19B38D3D831EF
1919
packages:
2020
- mono-devel
2121
- ca-certificates-mono
22-
- dotnet-hostfxr-2.0.0
23-
- dotnet-runtime-2.0.0
24-
- dotnet-sdk-2.0.0
22+
- dotnet-hostfxr-2.2
23+
- dotnet-runtime-2.2
24+
- dotnet-sdk-2.2
2525

2626
- python: 3.5
2727
env: *xplat-env
@@ -45,9 +45,9 @@ matrix:
4545
packages:
4646
- mono-devel
4747
- ca-certificates-mono
48-
- dotnet-hostfxr-2.0.0
49-
- dotnet-runtime-2.0.0
50-
- dotnet-sdk-2.0.0
48+
- dotnet-hostfxr-2.2
49+
- dotnet-runtime-2.2
50+
- dotnet-sdk-2.2
5151

5252
# --------------------- Classic builds ------------------------
5353
- python: 2.7
@@ -84,7 +84,7 @@ env:
8484
addons:
8585
apt:
8686
sources:
87-
- sourceline: deb http://download.mono-project.com/repo/ubuntu trusty main
87+
- sourceline: deb http://download.mono-project.com/repo/ubuntu xenial main
8888
key_url: http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xA6A19B38D3D831EF
8989
packages:
9090
- mono-devel

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1313

1414
### Changed
1515

16+
- Added argument types information to "No method matches given arguments" message
17+
1618
### Fixed
1719

1820
## [2.4.0][]

src/embed_tests/TestCallbacks.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
3+
using NUnit.Framework;
4+
using Python.Runtime;
5+
6+
namespace Python.EmbeddingTest {
7+
using Runtime = Python.Runtime.Runtime;
8+
9+
public class TestCallbacks {
10+
[OneTimeSetUp]
11+
public void SetUp() {
12+
PythonEngine.Initialize();
13+
}
14+
15+
[OneTimeTearDown]
16+
public void Dispose() {
17+
PythonEngine.Shutdown();
18+
}
19+
20+
[Test]
21+
public void TestNoOverloadException() {
22+
int passed = 0;
23+
var aFunctionThatCallsIntoPython = new Action<int>(value => passed = value);
24+
using (Py.GIL()) {
25+
dynamic callWith42 = PythonEngine.Eval("lambda f: f([42])");
26+
var error = Assert.Throws<PythonException>(() => callWith42(aFunctionThatCallsIntoPython.ToPython()));
27+
Assert.AreEqual("TypeError", error.PythonTypeName);
28+
string expectedArgTypes = Runtime.IsPython2
29+
? "(<type 'list'>)"
30+
: "(<class 'list'>)";
31+
StringAssert.EndsWith(expectedArgTypes, error.Message);
32+
}
33+
}
34+
}
35+
}

src/embed_tests/TestRuntime.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using NUnit.Framework;
33
using Python.Runtime;
4+
using Python.Runtime.Platform;
45

56
namespace Python.EmbeddingTest
67
{
@@ -26,10 +27,10 @@ public static void PlatformCache()
2627
{
2728
Runtime.Runtime.Initialize();
2829

29-
Assert.That(Runtime.Runtime.Machine, Is.Not.EqualTo(Runtime.Runtime.MachineType.Other));
30+
Assert.That(Runtime.Runtime.Machine, Is.Not.EqualTo(MachineType.Other));
3031
Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.MachineName));
3132

32-
Assert.That(Runtime.Runtime.OperatingSystem, Is.Not.EqualTo(Runtime.Runtime.OperatingSystemType.Other));
33+
Assert.That(Runtime.Runtime.OperatingSystem, Is.Not.EqualTo(OperatingSystemType.Other));
3334
Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.OperatingSystemName));
3435

3536
// Don't shut down the runtime: if the python engine was initialized
@@ -39,7 +40,7 @@ public static void PlatformCache()
3940
[Test]
4041
public static void Py_IsInitializedValue()
4142
{
42-
Runtime.Runtime.Py_Finalize();
43+
Runtime.Runtime.Py_Finalize();
4344
Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized());
4445
Runtime.Runtime.Py_Initialize();
4546
Assert.AreEqual(1, Runtime.Runtime.Py_IsInitialized());

src/runtime/Python.Runtime.15.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
3131
<PythonBuildDir Condition="'$(PythonBuildDir)' == ''">$(SolutionDir)\bin\</PythonBuildDir>
3232
<PublishDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)\$(TargetFramework)\</PublishDir>
33-
<LangVersion>6</LangVersion>
33+
<LangVersion>7.3</LangVersion>
3434
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
3535
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
3636
<CustomDefineConstants Condition="'$(CustomDefineConstants)' == ''">$(PYTHONNET_DEFINE_CONSTANTS)</CustomDefineConstants>

src/runtime/Python.Runtime.csproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
1616
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
1717
<AppDesignerFolder>Properties</AppDesignerFolder>
18-
<LangVersion>6</LangVersion>
18+
<LangVersion>7.3</LangVersion>
1919
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2020
<SignAssembly>false</SignAssembly>
2121
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
@@ -140,6 +140,8 @@
140140
<Compile Include="typemanager.cs" />
141141
<Compile Include="typemethod.cs" />
142142
<Compile Include="Util.cs" />
143+
<Compile Include="platform\Types.cs" />
144+
<Compile Include="platform\LibraryLoader.cs" />
143145
</ItemGroup>
144146
<ItemGroup Condition=" '$(PythonInteropFile)' != '' ">
145147
<Compile Include="$(PythonInteropFile)" />

src/runtime/methodbinder.cs

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Reflection;
4+
using System.Text;
45

56
namespace Python.Runtime
67
{
@@ -555,12 +556,36 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i
555556

556557
if (binding == null)
557558
{
558-
var value = "No method matches given arguments";
559+
var value = new StringBuilder("No method matches given arguments");
559560
if (methodinfo != null && methodinfo.Length > 0)
560561
{
561-
value += $" for {methodinfo[0].Name}";
562+
value.Append($" for {methodinfo[0].Name}");
562563
}
563-
Exceptions.SetError(Exceptions.TypeError, value);
564+
565+
long argCount = Runtime.PyTuple_Size(args);
566+
value.Append(": (");
567+
for(long argIndex = 0; argIndex < argCount; argIndex++) {
568+
var arg = Runtime.PyTuple_GetItem(args, argIndex);
569+
if (arg != IntPtr.Zero) {
570+
var type = Runtime.PyObject_Type(arg);
571+
if (type != IntPtr.Zero) {
572+
try {
573+
var description = Runtime.PyObject_Unicode(type);
574+
if (description != IntPtr.Zero) {
575+
value.Append(Runtime.GetManagedString(description));
576+
Runtime.XDecref(description);
577+
}
578+
} finally {
579+
Runtime.XDecref(type);
580+
}
581+
}
582+
}
583+
584+
if (argIndex + 1 < argCount)
585+
value.Append(", ");
586+
}
587+
value.Append(')');
588+
Exceptions.SetError(Exceptions.TypeError, value.ToString());
564589
return IntPtr.Zero;
565590
}
566591

0 commit comments

Comments
 (0)