Skip to content

Enable C# parameters of type object accept any argument, passed from Python #853

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

Merged
merged 4 commits into from
Jun 17, 2019

Conversation

lostmsu
Copy link
Member

@lostmsu lostmsu commented Apr 24, 2019

What does this implement/fix? Explain your changes.

Previously when a C# method with a parameter of type object was called from Python with some argument of a native Python type (e.g. instance of dict rather than instance of System.Random), that would be considered a parameter type mismatch, so overload resolution would fail, and the C# method would not be called.

After this change, when Python tries to pass a argument of some Python type to a C# parameter of type object, that overload would be considered good for resolution, and the argument will be wrapped into PyObject and passed to the object parameter.

For example:

void CallMe(object anything) => Console.WriteLine(anything);
CallMe(dict())

Before change: overload not found
After change: anything in CallMe is an instance of PyObject, wrapping a dict instance, so CallMe outputs {}

Does this close any currently open issues?

#811

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

lostmsu and others added 3 commits April 23, 2019 22:19
…instead of failing

This enables overload resolution with object parameters to behave the same way PyObject parameters behave - e.g. allow any Python object to be passed as PyObject as fallback.

Resolves pythonnet#811
@codecov
Copy link

codecov bot commented Apr 30, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@33db56d). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #853   +/-   ##
=========================================
  Coverage          ?   77.01%           
=========================================
  Files             ?       64           
  Lines             ?     5935           
  Branches          ?      975           
=========================================
  Hits              ?     4571           
  Misses            ?     1034           
  Partials          ?      330
Flag Coverage Δ
#setup_linux 65.3% <ø> (?)
#setup_windows 76.24% <100%> (?)
Impacted Files Coverage Δ
src/runtime/converter.cs 82.57% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 33db56d...4dd10b1. Read the comment docs.

@filmor filmor merged commit 43c972d into pythonnet:master Jun 17, 2019
filmor added a commit that referenced this pull request Jun 17, 2019
filmor added a commit that referenced this pull request Jun 20, 2019
@filmor
Copy link
Member

filmor commented Jun 20, 2019

Could you please reopen this?

@lostmsu
Copy link
Member Author

lostmsu commented Jun 20, 2019

@filmor , am I understanding it correctly, that Python-based tests need to be fixed appropriately?

@filmor
Copy link
Member

filmor commented Jun 20, 2019

I didn't check yet in detail what this PR broke, I just want to keep it on the radar :)

AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this pull request Jun 18, 2020
…m Python (pythonnet#853)

* added a regression test for pythonnet#881

pythonnet#811

* when converting to object, wrap values of unknown type into PyObject instead of failing

This enables overload resolution with object parameters to behave the same way PyObject parameters behave - e.g. allow any Python object to be passed as PyObject as fallback.

Resolves pythonnet#811
AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this pull request Jun 18, 2020
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