FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added `ToPythonAs()` extension method for explicit conversion using an arbitrary type by joaompneves · Pull Request #2419 · pythonnet/pythonnet · GitHub

Repository navigation

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

Open
joaompneves wants to merge 14 commits into
pythonnet:masterfrom
joaompneves:support-specific-type-encoding
Open

joaompneves wants to merge 14 commits into
pythonnet:masterfrom
joaompneves:support-specific-type-encoding

Conversation

joaompneves commented Jul 17, 2024 •
edited
Loading

Copy link
Copy Markdown

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 commented Jul 17, 2024 •
edited
Loading

Copy link
Copy Markdown
Member

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

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think this should be conditioned on not running in CI

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

joaompneves marked this pull request as ready for review July 18, 2024 17:17

Copy link
Copy Markdown
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.


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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think this should be conditioned on not running in CI

Comment thread src/runtime/Converter.cs
Comment on lines 138 to 140
/// </remarks>
public static PyObject FromManagedObject(object ob)
public static PyObject FromManagedObject(object ob, Type? type = null)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 requested a review from lostmsu July 29, 2024 14:25

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL