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

Drop List and IEnumerable conversions#963

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

Conversation

filmor
Copy link
Member

What does this implement/fix? Explain your changes.

Drop implicit conversion ofList<> andIEnumerable.

Does this close any currently open issues?

Heaps, I'll list them later

Any other comments?

Breaks the interface, so we'll have to announce this loudly and raise the minor version number.

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Add yourself toAUTHORS
  • Updated theCHANGELOG

mungojam and jlkittle reacted with thumbs up emoji
@filmorfilmorforce-pushed thedisable-implicit-list-conversion branch 2 times, most recently from6e202f6 tof1df348CompareSeptember 27, 2019 06:14
@filmorfilmorforce-pushed thedisable-implicit-list-conversion branch fromf1df348 toea8df83CompareSeptember 27, 2019 06:26
@lostmsu
Copy link
Member

Just want to confirm if we are to bump up major version with it. Seems like a non-trivial change, that might break a lot of things, that are working now.

It is not immediately obvious from this change, but if I used to pass an array to a parameter, that expects Pythonlist, would this no longer work anymore?

@filmor
Copy link
MemberAuthor

I'm trying to keep the amount of changes in behaviour to a minimum. I'm not going to bump the major version (i.e. this will not be 3.0) but instead the minor version 2.5 as I've had enough of the "lists behave weirdly" kind of issues we are seeing since this was introduced.

.NET array objects are stillIEnumerable<> and thus will keep being iterable, so for Python functions that don't (wrongly) check the type explicitly this will still work. We can as a further step also implement the Python Sequence Protocol forICollection<>, but one step after another :)

@lostmsu
Copy link
Member

@filmor what about functions, that dolen(arg)?

@filmor
Copy link
MemberAuthor

That is the second paragraph of my comment ;)

IEnumerable doesn't allow you to do an efficientlen either, that's whatICollection<> is for and we would have to implement at leastsq_len then.

@lostmsu
Copy link
Member

@filmor I meant that previously when you pass aList<T> to a Python function, that useslen(lst) it would work, but ifList<T> is no longer converted tolist, that will stop working.

@filmor
Copy link
MemberAuthor

filmor commentedSep 30, 2019
edited
Loading

List<T> implementsICollection<T> which has aCount property which should in turn be used to implement thesq_length slot of the sequence protocol (https://docs.python.org/3/c-api/typeobj.html#sequence-object-structures)

@lostmsu
Copy link
Member

@filmor "should be used" but not "already used". Are you planning to implementsq_length too before the next release?

@filmor
Copy link
MemberAuthor

This PR is a draft, I plan to work on it until all tests pass. If that means implementingsq_length, then that's what I am going to do.

lostmsu reacted with thumbs up emoji

@Cronan
Copy link
Contributor

What's the rationale for this please?

@filmor
Copy link
MemberAuthor

The rationale is the huge number of issues related to the automatic conversion. Just being able to use a .NETIEnumerable as an iterable andICollection as a sequence from Python catches most use cases of the conversion without breaking code likel = obj.GetCSharpList(); obj.CallWithCSharpList(l).

@Cronan
Copy link
Contributor

The rationale is the huge number of issues related to the automatic conversion. Just being able to use a .NETIEnumerable as an iterable andICollection as a sequence from Python catches most use cases of the conversion without breaking code likel = obj.GetCSharpList(); obj.CallWithCSharpList(l).

OK, thanks. It would be nice to close down a bunch of issues.

@Cronan
Copy link
Contributor

Any chance of getting a look at those issues?

@koubaa
Copy link
Contributor

@filmor@lostmsu Even if we drop it if we provide a codec (see 1022) that is not registered by default users can easily opt back into the current behavior by registering it themselves.

@mmisol
Copy link

@filmor First of all, thanks for providing such a great library!

Do you think this can go in as part of the 2.5 release? I see it's not in the RC, but would love to see this fixed.

@filmor
Copy link
MemberAuthor

@mmisol Sorry, 2.5 is a minor release, we can't break the API even though it would be an improvement.

@lostmsu
Copy link
Member

lostmsu commentedJun 11, 2020
edited
Loading

@mmisol injecting a no-op codec will allow you to override this behavior with 2.5:https://github.com/pythonnet/pythonnet/blob/master/src/runtime/Codecs/RawProxyEncoder.cs

E.g. (might contain errors)

classRawListEncoder:RawProxyEncoder{publicoverrideboolCanEncode(Typetype)=>type.IsGenericType&&type.GetGenericTypeDefinition()==typeof(List<>);}PyObjectConversions.RegisterEncoder(newRawListEncoder());

See also an example from Python side:f707698#diff-f8910e440ff4d17505744bd4c7016697R706

mmisol, filmor, and danabr reacted with thumbs up emoji

@lostmsu
Copy link
Member

lostmsu commentedDec 25, 2021
edited
Loading

I think this has been superseded in 3.0 branch. These default conversions are no longer enabled but can be reimplemented with codecs.

@filmorfilmor deleted the disable-implicit-list-conversion branchDecember 25, 2021 22:49
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@filmor@lostmsu@Cronan@koubaa@mmisol

[8]ページ先頭

©2009-2025 Movatter.jp