Skip to content

Added ToPythonAs() extension method for explicit conversion using an arbitrary type #2419

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

joaompneves
Copy link

@joaompneves joaompneves commented Jul 17, 2024

What does this implement/fix? Explain your changes.

When you have an object that implements multiple interfaces in an explicit way, there's no easy way to specify which of the interface we want to encode, when the interface type is not known at build time.
This PR allows that, by introducing an overload with and extra type parameter in the ToPythonAs method.
...

Does this close any currently open issues?

...

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 to AUTHORS
  • Updated the CHANGELOG

@lostmsu
Copy link
Member

lostmsu commented Jul 17, 2024

Can you please provide an example of how this can be used? Even better if it is a real-world usage example.

@joaompneves joaompneves changed the title Encoders no support specifying the target encoding type Added ToPythonAs() extension method for explicit conversion using an arbitrary type Jul 18, 2024
joaompneves and others added 4 commits July 18, 2024 18:10
@microsoft-github-policy-service agree
Revert unintentional changes
@@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<RollForward>LatestMajor</RollForward>
Copy link
Author

Choose a reason for hiding this comment

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

This allows anyone that has recent versions of .net to run these tests. I can revert but I think its usefull, otherwise one needs to install .net6 which is already deprecated

Copy link
Member

Choose a reason for hiding this comment

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

I think this should be conditioned on not running in CI

Copy link
Author

Choose a reason for hiding this comment

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

Is there any config/env var which I can check?

@joaompneves joaompneves marked this pull request as ready for review July 18, 2024 17:17
@joaompneves
Copy link
Author

Can you please provide an example of how this can be used? Even better if it is a real-world usage example.

Added a test.

@@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<RollForward>LatestMajor</RollForward>
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be conditioned on not running in CI

Comment on lines 139 to 140
public static PyObject FromManagedObject(object ob)
public static PyObject FromManagedObject(object ob, Type? type = null)
{
Copy link
Member

Choose a reason for hiding this comment

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

We need a use case and a test for this change as well.

Also, you have to add a separate overload because AFAIK adding default arguments breaks binary compatibility (e.g. libs compiled prior to this change will fail with MissingMethodException when they'll try to call the original method)

…oaompneves/pythonnet into support-specific-type-encoding

* 'support-specific-type-encoding' of https://github.com/joaompneves/pythonnet:
  Update CHANGELOG.md
  Update CHANGELOG.md
  Update CHANGELOG.md
@joaompneves joaompneves requested a review from lostmsu July 29, 2024 14:25
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.

2 participants