Skip to content

Enable C# objects to be callable #890

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 Jun 20, 2019 · 0 comments
Closed

Enable C# objects to be callable #890

lostmsu opened this issue Jun 20, 2019 · 0 comments
Milestone

Comments

@lostmsu
Copy link
Member

lostmsu commented Jun 20, 2019

Environment

  • Pythonnet version: 2.4.0
  • Python version: ANY
  • Operating System: ANY

Details

Given C# class Callable

class Callable {
  public int __call__(int arg) => arg * 2;
}

Be able call an instance of it like a function in Python:

callable = Callable()
print(callable(21))

Expected: should print 42
Actual: TypeError : object is not callable

Note

I am actually working on this. This is a tracking issue to reference in commits.

lostmsu added a commit to losttech/pythonnet that referenced this issue Jun 20, 2019
lostmsu added a commit to losttech/pythonnet that referenced this issue Jun 24, 2019
…e also callable now

A test case added to CallableObject.cs

When tp_call is invoked for a custom .NET class, and __call__ is not implemented in .NET, walk the class hierarchy (as seen from Python) until Python class is found. Then try to invoke its __call__ method, if defined.

pythonnet#890
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 6, 2021
Implemented by adding tp_call to ClassBase, that uses reflection to find __call__ methods in .NET, and falls back to invoking __call__ method from Python base classes.

fixes pythonnet#890

this is an amalgamation of d46878c,  5bb1007, and 960457f from https://github.com/losttech/pythonnet
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 6, 2021
Implemented by adding tp_call to ClassBase, that uses reflection to find __call__ methods in .NET, and falls back to invoking __call__ method from Python base classes.

fixes pythonnet#890

this is an amalgamation of d46878c,  5bb1007, and 960457f from https://github.com/losttech/pythonnet
@lostmsu lostmsu added this to the 3.0.0 milestone Oct 6, 2021
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 6, 2021
Implemented by adding tp_call to ClassBase, that uses reflection to find __call__ methods in .NET, and falls back to invoking __call__ method from Python base classes.

fixes pythonnet#890

this is an amalgamation of d46878c,  5bb1007, and 960457f from https://github.com/losttech/pythonnet
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 6, 2021
Implemented by adding tp_call to ClassBase, that uses reflection to find __call__ methods in .NET, and falls back to invoking __call__ method from Python base classes.

fixes pythonnet#890

this is an amalgamation of d46878c,  5bb1007, and 960457f from https://github.com/losttech/pythonnet
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 6, 2021
Implemented by adding tp_call to ClassBase, that uses reflection to find __call__ methods in .NET, and falls back to invoking __call__ method from Python base classes.

fixes pythonnet#890

this is an amalgamation of d46878c,  5bb1007, and 960457f from https://github.com/losttech/pythonnet
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 7, 2021
Implemented by adding tp_call to ClassBase, that uses reflection to find __call__ methods in .NET

fixes pythonnet#890

this is an amalgamation of d46878c,  5bb1007, and 960457f from https://github.com/losttech/pythonnet
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 7, 2021
Implemented by adding tp_call to ClassBase, that uses reflection to find __call__ methods in .NET

fixes pythonnet#890

this is an amalgamation of d46878c,  5bb1007, and 960457f from https://github.com/losttech/pythonnet
@filmor filmor closed this as completed in bc3265d Oct 14, 2021
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

1 participant