| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 451fae6 commit b5ba815
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ | |||
| 28 | 28 | - Christoph Gohlke ([@cgohlke](https://github.com/cgohlke)) | |
| 29 | 29 | - Christopher Bremner ([@chrisjbremner](https://github.com/chrisjbremner)) | |
| 30 | 30 | - Christopher Pow ([@christopherpow](https://github.com/christopherpow)) | |
| 31 | + - Daniel Abrahamsson ([@danabr](https://github.com/danabr)) | ||
| 31 | 32 | - Daniel Fernandez ([@fdanny](https://github.com/fdanny)) | |
| 32 | 33 | - Daniel Santana ([@dgsantana](https://github.com/dgsantana)) | |
| 33 | 34 | - Dave Hirschfeld ([@dhirschfeld](https://github.com/dhirschfeld)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ details about the cause of the failure | |||
| 21 | 21 | - Fix incorrect dereference of wrapper object in `tp_repr`, which may result in a program crash | |
| 22 | 22 | - Fix incorrect dereference in params array handling | |
| 23 | 23 | - Fix `object[]` parameters taking precedence when should not in overload resolution | |
| 24 | + - Fixed a bug where all .NET class instances were considered Iterable | ||
| 24 | 25 | ||
| 25 | 26 | ## [2.5.0][] - 2020-06-14 | |
| 26 | 27 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -164,6 +164,13 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType) | |||
| 164 | 164 | // we want to do this after the slot stuff above in case the class itself implements a slot method | |
| 165 | 165 | InitializeSlots(type, impl.GetType()); | |
| 166 | 166 | ||
| 167 | + if (!clrType.GetInterfaces().Any(ifc => ifc == typeof(IEnumerable) || ifc == typeof(IEnumerator))) | ||
| 168 | + { | ||
| 169 | + // The tp_iter slot should only be set for enumerable types. | ||
| 170 | + Marshal.WriteIntPtr(type, TypeOffset.tp_iter, IntPtr.Zero); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + | ||
| 167 | 174 | if (base_ != IntPtr.Zero) | |
| 168 | 175 | { | |
| 169 | 176 | Marshal.WriteIntPtr(type, TypeOffset.tp_base, base_); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -172,6 +172,23 @@ def test_ienumerator_iteration(): | |||
| 172 | 172 | for item in chars: | |
| 173 | 173 | assert item in 'test string' | |
| 174 | 174 | ||
| 175 | + def test_iterable(): | ||
| 176 | + """Test what objects are Iterable""" | ||
| 177 | + from collections.abc import Iterable | ||
| 178 | + from Python.Test import ClassTest | ||
| 179 | + | ||
| 180 | + assert isinstance(System.String.Empty, Iterable) | ||
| 181 | + assert isinstance(ClassTest.GetArrayList(), Iterable) | ||
| 182 | + assert isinstance(ClassTest.GetEnumerator(), Iterable) | ||
| 183 | + assert (not isinstance(ClassTest, Iterable)) | ||
| 184 | + assert (not isinstance(ClassTest(), Iterable)) | ||
| 185 | + | ||
| 186 | + class ShouldBeIterable(ClassTest): | ||
| 187 | + def __iter__(self): | ||
| 188 | + return iter([]) | ||
| 189 | + | ||
| 190 | + assert isinstance(ShouldBeIterable(), Iterable) | ||
| 191 | + | ||
| 175 | 192 | ||
| 176 | 193 | def test_override_get_item(): | |
| 177 | 194 | """Test managed subclass overriding __getitem__.""" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments