Implement IConvertible on PyObject#1762
Conversation
|
.NET team now avoids |
|
See also dotnet/runtime#62022 |
|
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. |
|
@filmor the new |
| return ToBigInteger().ToString(format, formatProvider); | ||
| } | ||
|
|
||
| public override TypeCode GetTypeCode() => TypeCode.Int64; |
There was a problem hiding this comment.
The docs are a bit unclear on this function. I used this as an "should almost always work" value, the InvalidCastException might still be thrown if the conversion fails. We could drop the GetTypeCode overrides entirely and just return TypeCode.Object if you'd prefer that.
There was a problem hiding this comment.
I can't say for others, just for this one. Honestly, not sure if anyone ever uses this. Our own code assumes TypeCode.Int64 refers to System.Int64, so removing might be a good idea.
There was a problem hiding this comment.
I'm not sure I follow. GetTypeCode is supposed to be a hint that allows you to write a switch like
switch (convertible.GetTypeCode()) {
case TypeCode.Int64:
return Convert.ToInt64(convertible);
}It doesn't mean that the object is a System.Int64 already.
There was a problem hiding this comment.
You seem to be correct on that. Still not sure Int64 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 returning Int64 any time soon.
What does this implement/fix? Explain your changes.
Implements the IConvertible interface for
PyObjectinstances.Does this close any currently open issues?
Should fix #1755.
Any other comments?
...
Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG