Skip to content

Retry: Enable C# parameters of type object accept any argument, passed from Python #889

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 6 commits into from
Mar 3, 2020

Conversation

lostmsu
Copy link
Member

@lostmsu lostmsu commented Jun 20, 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

P.S.

This is a retry of #853

@lostmsu
Copy link
Member Author

lostmsu commented Jun 20, 2019

@filmor is there an instruction to run Python unit tests?

@filmor
Copy link
Member

filmor commented Jun 20, 2019

You can run the unit tests by using pytest (either just pytest or python -m pytest) after installing.

@lostmsu lostmsu force-pushed the PR/ObjectAcceptsAll branch from 9e07d3a to f83d8fc Compare October 21, 2019 19:35
@codecov-io
Copy link

codecov-io commented Oct 21, 2019

Codecov Report

Merging #889 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #889   +/-   ##
=======================================
  Coverage   86.75%   86.75%           
=======================================
  Files           1        1           
  Lines         302      302           
=======================================
  Hits          262      262           
  Misses         40       40
Flag Coverage Δ
#setup_linux 65.56% <ø> (ø) ⬆️
#setup_windows 71.52% <ø> (ø) ⬆️

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 6373197...133ac84. Read the comment docs.

@lostmsu
Copy link
Member Author

lostmsu commented Oct 21, 2019

@filmor AppVeyor failed for 3.6 x86 due to connectivity issue on the VM: https://ci.appveyor.com/project/pythonnet/pythonnet/builds/28271316 . Results are not being picked up.

@lostmsu lostmsu requested a review from filmor October 24, 2019 20:37
…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
@lostmsu lostmsu force-pushed the PR/ObjectAcceptsAll branch from 2f7b0e9 to 102239a Compare February 27, 2020 05:04
@lostmsu lostmsu force-pushed the PR/ObjectAcceptsAll branch from 102239a to 6373197 Compare February 27, 2020 05:06
@lostmsu lostmsu added this to the 2.4.1 milestone Feb 27, 2020
@lostmsu lostmsu requested a review from filmor March 2, 2020 23:47
@filmor filmor merged commit 8ad1062 into pythonnet:master Mar 3, 2020
@lostmsu lostmsu modified the milestones: 2.4.1, 2.5.0 Apr 23, 2020
AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this pull request Jun 29, 2020
…m Python (pythonnet#889)

* added a regression test for pythonnet#881
* 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

* fixed ObjectField conversion test
* fixed test_object_indexer to pass on custom class key
* use object() instance in OverloadResolution_UnknownToObject test
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