Skip to content

An overload with a parameter of type object is not used #811

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

Closed
lostmsu opened this issue Jan 28, 2019 · 3 comments
Closed

An overload with a parameter of type object is not used #811

lostmsu opened this issue Jan 28, 2019 · 3 comments

Comments

@lostmsu
Copy link
Member

lostmsu commented Jan 28, 2019

Environment

  • Pythonnet version: 2.3.0
  • Python version: 3.6
  • Operating System: Win 10 x64 1809

Details

I am trying to get Python call my C# method, which has a parameter of type object with an instance of Python's KeyError.

var o = overloaded.ToPython();

dynamic callWithSelf = PythonEngine.Eval("lambda o: o.ObjOrClass(KeyError())");
callWithSelf(o);

Where ObjOrClass definition is: public void ObjOrClass(object _) => this.Value = Object;. The actual function body here is not important.

  • Error:
Python.Runtime.PythonException : TypeError : No method matches given arguments for ObjOrClass

Possibly related:

#265
#782

Thoughs

IMHO, Python.NET should create a PyObject and pass it here.

lostmsu added a commit to losttech/pythonnet that referenced this issue Jan 28, 2019
lostmsu added a commit to losttech/pythonnet that referenced this issue Feb 11, 2019
…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 added a commit to losttech/pythonnet that referenced this issue Feb 11, 2019
@filmor
Copy link
Member

filmor commented Mar 6, 2019

Yes, it's a possibility to do that. The issue at hand is probably, that Python objects do not derive from System.Object and can thus not match the overload. Can you prepare a PR?

@lostmsu
Copy link
Member Author

lostmsu commented Apr 14, 2019

@filmor I am not sure I understood your comment. You can see my fix in the commit e9712b4 above. This change is potentially backwards-incompatible in case there's a .NET method with two overloads, one having parameter type object, and another PyObject for some parameter.

@filmor
Copy link
Member

filmor commented Apr 23, 2019

I'll need to look into this, could you make a PR from this commit?

lostmsu added a commit to losttech/pythonnet that referenced this issue Apr 24, 2019
lostmsu added a commit to losttech/pythonnet that referenced this issue Apr 24, 2019
…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
@filmor filmor closed this as completed in 43c972d Jun 17, 2019
lostmsu added a commit to losttech/pythonnet that referenced this issue Jun 26, 2019
filmor pushed a commit that referenced this issue Jun 28, 2019
…#900)

* generate more useful message, when a .NET overload can't be found, that matches Python parameter types
* provide detailed error message, when an overload can't be found when calling C# from Python

Related: #811, #265, #782
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 21, 2019
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 21, 2019
…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 added a commit to losttech/pythonnet that referenced this issue Feb 27, 2020
lostmsu added a commit to losttech/pythonnet that referenced this issue Feb 27, 2020
…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
filmor pushed a commit that referenced this issue Mar 3, 2020
…m Python (#889)

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

* fixed ObjectField conversion test
* fixed test_object_indexer to pass on custom class key
* use object() instance in OverloadResolution_UnknownToObject test
lostmsu added a commit to losttech/pythonnet that referenced this issue May 14, 2020
…tails

Similar to pythonnet#900, but for constructors (reuses the same code)

Related issues: pythonnet#811, pythonnet#265, pythonnet#1116
filmor pushed a commit that referenced this issue May 14, 2020
…tails (#1143)

Similar to #900, but for constructors (reuses the same code)

Related issues: #811, #265, #1116
AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this issue 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 issue Jun 18, 2020
…pythonnet#900)

* generate more useful message, when a .NET overload can't be found, that matches Python parameter types
* provide detailed error message, when an overload can't be found when calling C# from Python

Related: pythonnet#811, pythonnet#265, pythonnet#782
AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this issue 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
AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this issue Jun 29, 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

No branches or pull requests

2 participants