FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Ensure only implementers of IEnumerable or IEnumerator are considered Iterable by danabr · Pull Request #1241 · pythonnet/pythonnet · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (1) .md  (2) .py  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions AUTHORS.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Christoph Gohlke ([@cgohlke](https://github.com/cgohlke))
- Christopher Bremner ([@chrisjbremner](https://github.com/chrisjbremner))
- Christopher Pow ([@christopherpow](https://github.com/christopherpow))
- Daniel Abrahamsson ([@danabr](https://github.com/danabr))
- Daniel Fernandez ([@fdanny](https://github.com/fdanny))
- Daniel Santana ([@dgsantana](https://github.com/dgsantana))
- Dave Hirschfeld ([@dhirschfeld](https://github.com/dhirschfeld))
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ details about the cause of the failure
- Fix incorrect dereference of wrapper object in `tp_repr`, which may result in a program crash
- Fix incorrect dereference in params array handling
- Fix `object[]` parameters taking precedence when should not in overload resolution
- Fixed a bug where all .NET class instances were considered Iterable

## [2.5.0][] - 2020-06-14

Expand Down
7 changes: 7 additions & 0 deletions src/runtime/typemanager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType)
// we want to do this after the slot stuff above in case the class itself implements a slot method
InitializeSlots(type, impl.GetType());

if (!clrType.GetInterfaces().Any(ifc => ifc == typeof(IEnumerable) || ifc == typeof(IEnumerator)))
{
// The tp_iter slot should only be set for enumerable types.
Marshal.WriteIntPtr(type, TypeOffset.tp_iter, IntPtr.Zero);
}


if (base_ != IntPtr.Zero)
{
Marshal.WriteIntPtr(type, TypeOffset.tp_base, base_);
Expand Down
17 changes: 17 additions & 0 deletions src/tests/test_class.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ def test_ienumerator_iteration():
for item in chars:
assert item in 'test string'

def test_iterable():
"""Test what objects are Iterable"""
from collections.abc import Iterable
from Python.Test import ClassTest

assert isinstance(System.String.Empty, Iterable)
assert isinstance(ClassTest.GetArrayList(), Iterable)
assert isinstance(ClassTest.GetEnumerator(), Iterable)
assert (not isinstance(ClassTest, Iterable))
assert (not isinstance(ClassTest(), Iterable))

class ShouldBeIterable(ClassTest):
def __iter__(self):
return iter([])

assert isinstance(ShouldBeIterable(), Iterable)


def test_override_get_item():
"""Test managed subclass overriding __getitem__."""
Expand Down

Back | FazBrowse Home | New Git URL