Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ensure only implementers of IEnumerable or IEnumerator are considered Iterable#1241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lostmsu merged 2 commits intopythonnet:masterfromdanabr:iterable
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
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
1 change: 1 addition & 0 deletionsAUTHORS.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssrc/runtime/typemanager.cs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssrc/tests/test_class.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp