Skip to content

Conversation

@mmisol
Copy link
Collaborator

@mmisol mmisol commented Jun 30, 2020

Purpose

Support is added for encoding decoding BigInteger values from Python
int that have a size that exceeds what can fit in a long.

Also a BigInteger encoder/decoder is added to the custom encoders of
Python.NET in order to support encoding and decoding in the context of
function calls.

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.

Reviewers

@DynamoDS/dynamo

@mmisol mmisol requested a review from a team June 30, 2020 20:04
@mjkkirschner
Copy link
Member

@mmisol 😢

(CoreCompile target) -> 
  Encoders\BigIntegerEncoder.cs(23,25): error CS8107: Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater. [C:\projects\dynamo\src\Libraries\DSCPython\DSCPython.csproj]
    2057 Warning(s)
    1 Error(s)
Time Elapsed 00:01:17.13

maybe time to retire this build and use our github action instead?

@mmisol
Copy link
Collaborator Author

mmisol commented Jun 30, 2020

Yeah. I saw that appveyor thing probably needs an update, but it's not even ours! Probably it is a good time to retire it. I read we should just remove the web hook and that's it.

/// </summary>
private static void InitializeEncoders()
{
var encoders = new IPyObjectEncoder[] { new BigIntegerEncoder() };
Copy link
Member

Choose a reason for hiding this comment

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

@aparajit-pratap these are the encoders I mentioned before.

Copy link
Contributor

@aparajit-pratap aparajit-pratap Jun 30, 2020

Choose a reason for hiding this comment

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

@mmisol was the biginteger encoder/decoder added by you? I may have missed it in your PR's to Python.NET repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BigIntegerEncoder is part of this submission. The API to add them already existed. One thing I did add in Python.NET is the function PyLong.ToBigInteger, which is used by the decoder.


namespace DSCPython.Encoders
{
internal class BigIntegerEncoder : IPyObjectEncoder, IPyObjectDecoder
Copy link
Member

Choose a reason for hiding this comment

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

thank you for making this internal!
🎉

</ProjectReference>
<ProjectReference Include="..\..\..\src\Tools\DynamoShapeManager\DynamoShapeManager.csproj">
<Project>{263fa9c1-f81e-4a8e-95e0-8cdae20f177b}</Project>
<Name>DynamoShapeManager</Name>
Copy link
Member

Choose a reason for hiding this comment

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

just curious about the requirement for these dependencies.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So, when you inherit from DynamoModelTestBase and want to customize CreateStartConfiguration you pass some parameters that will complain because you don't have these.

Copy link
Member

Choose a reason for hiding this comment

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

ahh, okay, generally I would say avoid loading libraries that we don't need during the test as these types will be imported into the VM over and over again for each test which can be kind of slow. So if we write 1000 ironPython tests we'll load all the geometry types into the VM foreach test.

@aparajit-pratap
Copy link
Contributor

Why are we spending a whole bunch of time with BigIntegers. They just happen to be supported by IronPython but not a big use case for zero touch nodes or even python nodes for that matter.


using (var pyLong = PyLong.AsLong(pyObj))
{
value = (T)(object)pyLong.ToBigInteger();
Copy link
Member

Choose a reason for hiding this comment

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

staring at this I'm assuming that PythonNet will only ever call this method when T is bigInteger ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. I think there is something strange with the definition of the interface because it's not a generic one but one of its methods is generic. I didn't know how to handle that exactly but I took this from an example they have in a test.

@mmisol
Copy link
Collaborator Author

mmisol commented Jul 2, 2020

Hi @mjkkirschner @aparajit-pratap . If there is nothing else missing here, can I ask for your approval? Thanks

}
return dict;
}
else if (PyLong.IsLongType(pyObj))
Copy link
Contributor

Choose a reason for hiding this comment

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

or here.

}
return list;
}
else if (PyDict.IsDictType(pyObj))
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for else here.

{
return pyLong.ToInt64();
}
catch (PythonException exc) when (exc.Message.StartsWith("OverflowError"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, I haven't seen a when clause like this before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are called exception filters. They allow to catch an exception type conditionally to the fact they also match the expression given in when. They were introduced in C# 6 https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-6#exception-filters

Copy link
Contributor

@aparajit-pratap aparajit-pratap left a comment

Choose a reason for hiding this comment

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

Minor comments; other than that LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants