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

Implement IConvertible on PyObject#1762

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 1 commit intopythonnet:masterfromfilmor:iconvertible
Apr 11, 2022

Conversation

filmor
Copy link
Member

@filmorfilmor commentedApr 10, 2022
edited
Loading

What does this implement/fix? Explain your changes.

Implements theIConvertible interface forPyObject instances.

Does this close any currently open issues?

Shouldfix#1755.

Any other comments?

...

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
  • Ensure you have signed the.NET Foundation CLA
  • Add yourself toAUTHORS
  • Updated theCHANGELOG

@lostmsu
Copy link
Member

.NET team now avoidsIConvertible:dotnet/runtime#936 (comment)

@lostmsu
Copy link
Member

See alsodotnet/runtime#62022

@filmor
Copy link
MemberAuthor

It doesn't look like there is an alternative yet, though, right? And I also don't think that they are actually going to drop the interface, they are just not extending it for new primitive types, which have no representation in Python anyway.

@lostmsu
Copy link
Member

@filmor the newHalf type does not implementIConvertible though it is nearly identical toSingle andDouble. So I guess it is kinda deprecated (not that I completely agree with everything .NET team does).

@@ -230,5 +230,7 @@ public string ToString(string format, IFormatProvider formatProvider)
using var _ = Py.GIL();
return ToBigInteger().ToString(format, formatProvider);
}

public override TypeCode GetTypeCode() => TypeCode.Int64;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Generally, this is wrong.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The docs are a bit unclear on this function. I used this as an "should almost always work" value, theInvalidCastException might still be thrown if the conversion fails. We could drop theGetTypeCode overrides entirely and just returnTypeCode.Object if you'd prefer that.

Copy link
Member

@lostmsulostmsuApr 10, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I can't say for others, just for this one. Honestly, not sure if anyone ever uses this. Our own code assumesTypeCode.Int64 refers toSystem.Int64, so removing might be a good idea.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not sure I follow.GetTypeCode is supposed to be a hint that allows you to write aswitch like

switch(convertible.GetTypeCode()){caseTypeCode.Int64:returnConvert.ToInt64(convertible);}

It doesn't mean that the objectis aSystem.Int64 already.

Copy link
Member

@lostmsulostmsuApr 10, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You seem to be correct on that. Still not sureInt64 is valid for this specific case, but float and string probably are. I am fine either way though. I don't think we will get people complaining about this returningInt64 any time soon.

@lostmsulostmsu merged commit80dc9f0 intopythonnet:masterApr 11, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@lostmsulostmsulostmsu left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Python int type is translated to pyInt when passed as a .net Dictionary value only in 3.x version
2 participants
@filmor@lostmsu

[8]ページ先頭

©2009-2025 Movatter.jp