Skip to content

Commit 5f63c67

Browse files
authored
BREAKING: disabled implicit conversion from Python objects implementing sequence protocol to (#1902)
.NET arrays when the target .NET type is `System.Object`. The conversion is still attempted when the target type is a `System.Array` fixes #1900
1 parent 85d0ca6 commit 5f63c67

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ or the DLL must be loaded in advance. This must be done before calling any other
6767
- BREAKING: disabled implicit conversion from C# enums to Python `int` and back.
6868
One must now either use enum members (e.g. `MyEnum.Option`), or use enum constructor
6969
(e.g. `MyEnum(42)` or `MyEnum(42, True)` when `MyEnum` does not have a member with value 42).
70+
- BREAKING: disabled implicit conversion from Python objects implementing sequence protocol to
71+
.NET arrays when the target .NET type is `System.Object`. The conversion is still attempted when the
72+
target type is a `System.Array`.
7073
- Sign Runtime DLL with a strong name
7174
- Implement loading through `clr_loader` instead of the included `ClrModule`, enables
7275
support for .NET Core

src/runtime/Converter.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,6 @@ internal static bool ToManagedValue(BorrowedReference value, Type obType,
389389
return true;
390390
}
391391

392-
if (Runtime.PySequence_Check(value))
393-
{
394-
return ToArray(value, typeof(object[]), out result, setError);
395-
}
396-
397392
result = new PyObject(value);
398393
return true;
399394
}

tests/test_conversion.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,13 @@ class Foo(object):
577577
ob.ObjectField = Foo
578578
assert ob.ObjectField == Foo
579579

580+
class PseudoSeq:
581+
def __getitem__(self, idx):
582+
return 0
583+
584+
ob.ObjectField = PseudoSeq()
585+
assert ob.ObjectField.__class__.__name__ == "PseudoSeq"
586+
580587

581588
def test_null_conversion():
582589
"""Test null conversion."""

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy