diff --git a/src/core/IronPython.StdLib b/src/core/IronPython.StdLib index 262178d82..b4f2595fa 160000 --- a/src/core/IronPython.StdLib +++ b/src/core/IronPython.StdLib @@ -1 +1 @@ -Subproject commit 262178d820a73203cb973a1a85eb9ab860bfafca +Subproject commit b4f2595fa163f64227c4a0b94c6e5ce1a4cdc31b diff --git a/src/core/IronPython/Runtime/Binding/PythonGetMemberBinder.cs b/src/core/IronPython/Runtime/Binding/PythonGetMemberBinder.cs index d730b5490..50ebe88ee 100644 --- a/src/core/IronPython/Runtime/Binding/PythonGetMemberBinder.cs +++ b/src/core/IronPython/Runtime/Binding/PythonGetMemberBinder.cs @@ -125,6 +125,8 @@ public override T BindDelegate(CallSite site, object[] args) { break; case "__file__": return (T)(object)new Func(new NamespaceTrackerDelegate(_name).GetFile); + case "__path__": + return (T)(object)new Func(new NamespaceTrackerDelegate(_name).GetPath); case "__dict__": return (T)(object)new Func(new NamespaceTrackerDelegate(_name).GetDict); case "__name__": @@ -622,6 +624,14 @@ public object GetFile(CallSite site, object self, CodeContext context) { return Update(site, self, context); } + public object GetPath(CallSite site, object self, CodeContext context) { + if (self != null && self.GetType() == typeof(NamespaceTracker)) { + return NamespaceTrackerOps.Get__path__((NamespaceTracker)self); + } + + return Update(site, self, context); + } + public object GetDict(CallSite site, object self, CodeContext context) { if (self != null && self.GetType() == typeof(NamespaceTracker)) { return NamespaceTrackerOps.Get__dict__(context, (NamespaceTracker)self); diff --git a/src/core/IronPython/Runtime/Operations/NamespaceTrackerOps.cs b/src/core/IronPython/Runtime/Operations/NamespaceTrackerOps.cs index 2b1b335b9..a8fffb125 100644 --- a/src/core/IronPython/Runtime/Operations/NamespaceTrackerOps.cs +++ b/src/core/IronPython/Runtime/Operations/NamespaceTrackerOps.cs @@ -39,11 +39,18 @@ public static string __repr__(NamespaceTracker self) { public static string __str__(NamespaceTracker self) { if (self.PackageAssemblies.Count != 1) { - return string.Format("", Get__name__(self.Name), self.PackageAssemblies.Count); + return string.Format("", self.Name, self.PackageAssemblies.Count); } - return string.Format("", Get__name__(self.Name), self.PackageAssemblies[0].FullName); + return string.Format("", self.Name, self.PackageAssemblies[0].FullName); } + /// + /// Namespaces are packages for importlib, but their children are not found on the file system, + /// so there are no locations to search. + /// + [SpecialName, PropertyMethod] + public static PythonList Get__path__(NamespaceTracker self) => new PythonList(); + [SpecialName, PropertyMethod] public static PythonDictionary Get__dict__(CodeContext context, NamespaceTracker self) { PythonDictionary res = new PythonDictionary(); @@ -57,16 +64,12 @@ public static PythonDictionary Get__dict__(CodeContext context, NamespaceTracker return res; } + /// + /// The full name of the namespace. + /// [SpecialName, PropertyMethod] public static string Get__name__(CodeContext context, NamespaceTracker self) { - return Get__name__(self.Name); - } - - private static string Get__name__(string name) { - int lastDot = name.LastIndexOf('.'); - if (lastDot == -1) return name; - - return name.Substring(lastDot + 1); + return self.Name; } [SpecialName] diff --git a/tests/suite/test_clrload.py b/tests/suite/test_clrload.py index cbda92e3c..2bebb6610 100644 --- a/tests/suite/test_clrload.py +++ b/tests/suite/test_clrload.py @@ -376,12 +376,12 @@ def test_local_dll(self): self.assertEqual(repr(x), "") self.assertEqual(repr(x.Foo), "") self.assertEqual(repr(x.BarNamespace), "") - self.assertEqual(repr(x.BarNamespace.NestedNamespace), "") + self.assertEqual(repr(x.BarNamespace.NestedNamespace), "") self.assertEqual(repr(x.BarNamespace.Bar.NestedBar), "") self.assertEqual(x.__dict__["BarNamespace"], x.BarNamespace) self.assertEqual(x.BarNamespace.__dict__["Bar"], x.BarNamespace.Bar) self.assertEqual(x.BarNamespace.__dict__["NestedNamespace"], x.BarNamespace.NestedNamespace) - self.assertEqual(x.BarNamespace.NestedNamespace.__name__, "NestedNamespace") + self.assertEqual(x.BarNamespace.NestedNamespace.__name__, "BarNamespace.NestedNamespace") self.assertEqual(x.BarNamespace.NestedNamespace.__file__, "c3, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null") self.assertRaises(AttributeError, lambda: x.BarNamespace.NestedNamespace.not_exist) self.assertRaises(AttributeError, lambda: x.Foo2) # assembly c3 has no type Foo2