Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improved AttributeError when looking for a symbol that does not exist…
… inside a .NET module.
  • Loading branch information
rmadsen-ks committed Oct 31, 2022
commit 7980fc4cf5cddab41856d181f57274568def9d3c
2 changes: 1 addition & 1 deletion src/python_tests_runner/PythonTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PythonTestRunner
public void SetUp()
{
Python.Runtime.Runtime.PythonDLL =
"/Library/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib";
"C:\\Python37.2\\python37.dll";
Comment on lines +20 to +21
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean up the history

PythonEngine.Initialize();
}

Expand Down
1 change: 1 addition & 0 deletions src/runtime/Types/ClassDerived.cs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ public class PythonDerivedType
internal static Dictionary<PyObject, List<PyTuple>> methodAssoc = new Dictionary<PyObject, List<PyTuple>>();
public static void PushAttribute(PyObject obj)
{
using var _ = Py.GIL();
var tp = new PyTuple(obj);
attributesStack.Add(tp);
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/Types/ModuleObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public static NewReference tp_getattro(BorrowedReference ob, BorrowedReference k

if (attr.IsNull())
{
Exceptions.SetError(Exceptions.AttributeError, name);
Exceptions.SetError(Exceptions.AttributeError, $"name '{name}' is not defined in module '{self.moduleName}'.");
return default;
}

Expand Down
9 changes: 8 additions & 1 deletion src/testing/subclasstest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ public interface ISimpleInterface
{
bool Ok();
}

public interface ISimpleInterface2
{
int Execute(CancellationToken token);
}
public class TestAttributeAttribute: Attribute
{
public int X { get; set; }
Expand Down Expand Up @@ -168,6 +171,10 @@ public static void TestObject(object obj)
if (!si.Ok())
throw new Exception();

}else if (obj is ISimpleInterface2 si2)
{
si2.Execute(CancellationToken.None);

}
else
{
Expand Down
18 changes: 17 additions & 1 deletion tests/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
from System import (Console, Attribute, Double)
from System.Diagnostics import (DebuggerDisplay, DebuggerDisplayAttribute, Debug)
from System.ComponentModel import (Browsable, BrowsableAttribute)
from System.Threading import (CancellationToken)
import pytest
from Python.Test import (IInterfaceTest, SubClassTest, EventArgsTest,
FunctionsTest, GenericVirtualMethodTest, ISimpleInterface, SimpleClass, TestAttribute, TestAttributeAttribute)
FunctionsTest, GenericVirtualMethodTest, ISimpleInterface, SimpleClass, TestAttribute, TestAttributeAttribute, ISimpleInterface2)
import Python.Test
from System.Collections.Generic import List


Expand Down Expand Up @@ -290,12 +292,26 @@ def Ok(self):
class DualSubClass2(ISimpleInterface):
def Ok(self):
return True
class DualSubClass3(ISimpleInterface2):
def Execute(self, cancellationToken):
return 0
try:
class DualSubClass4(Python.Test.ISimpleInterface3):
def Execute(self, cancellationToken):
return 0
assert False # An exception should be thrown.
except AttributeError as ae:
assert ("not defined" in str(ae))

obj = DualSubClass()
SimpleClass.TestObject(obj)
obj = DualSubClass2()
SimpleClass.TestObject(obj)

obj2 = DualSubClass3();
SimpleClass.TestObject(obj2)
#obj2.Execute(CancellationToken.None)

def test_class_with_attributes():
import clr
@clr.attribute(Browsable(False))
Expand Down