Skip to content
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

Python bindings: call to Port.setReporter() raises TypeError #2882

Open
hypothe opened this issue Sep 29, 2022 · 1 comment
Open

Python bindings: call to Port.setReporter() raises TypeError #2882

hypothe opened this issue Sep 29, 2022 · 1 comment

Comments

@hypothe
Copy link
Contributor

hypothe commented Sep 29, 2022

Describe the bug
I'm trying to attach a custom PortReporter to a Port using the python bindings, but a TypeError is raised complaining about the type of the PortReporter.

To Reproduce
Minimal script to reproduce:

import yarp

class MyPortReport(yarp.PortReport):
    def __init__(self, *args, **kwargs):
        print("MyPortReport INIT")
    def report(self, info):
        print("MyPortReport REPORT")

port = yarp.Port()
report = MyPortReport()

port.setReporter(report)

The creation goes through smoothly, but the call to setReporter raises:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/src/robot/robotology-superbuild/build/install/lib/python3/dist-packages/yarp.py", line 1532, in setReporter
    return _yarp.Port_setReporter(self, reporter)
TypeError: in method 'Port_setReporter', argument 2 of type 'yarp::os::PortReport &'

Configuration:

  • OS: Ubuntu 20.04
  • yarp version: 3.6.0
  • compiler: ///
@traversaro
Copy link
Member

Hello @hypothe ! The callback machinery in SWIG is not immediate, as it requires the use of the "directors" feature, see https://www.swig.org/Doc4.0/SWIGDocumentation.html#SWIGPlus_target_language_callbacks and https://www.swig.org/Doc4.0/SWIGDocumentation.html#Python_nn33 .

At a first glance, it seems that callback in Python are working fine for the useCallback function of yarp::os::BufferedPort, see

. Probably this is due to the lines in yarp.i such as
%feature("director") yarp::os::TypedReaderCallback<name>;
and the following lines.

Perhaps adding %feature("director") yarp::os::PortReport; in

%feature("director") yarp::os::PortReader;
and recompiling and install YARP and the YARP python bindings could fix the problem. If you are able to test it and it works, feel free to submit a PR, thanks!

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