-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[ENH] Multiple inputs for OWPythonScript #2506
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2506 +/- ##
==========================================
+ Coverage 75.02% 75.03% +<.01%
==========================================
Files 327 327
Lines 57641 57700 +59
==========================================
+ Hits 43248 43297 +49
- Misses 14393 14403 +10 |
I like the idea, hate the metaclass. IIUC the metaclass (1) creates the signals, (2) handlers and (3) fills the input_name and output_names lists with the names of the signals. (1) I would keep the input/output declarations on the widget, it is a bit more verbose, but allows us easier modification. If at some point we decide to rename classifier input to model, and need to add replaces attribute to the Input/Output, that is much easier with explicit signal declarations. (2) I would much rather have the handler method on the widget, with metaclass adding (and registering) thin methods that call the actual handler with the correct parameters. (3) do we really need these? They could be a property that calls getmembers on Intputs/Outputs |
At first, I almost did it without the meta class. Everything that the meta class does can be done in the widget class itself, but too late: the meta class of OWWidget (WidgetMetaClass) calls a method (3) are not needed. I added them just to minimize the number of changes, but I'm happy to remove them. Suggestions (1) and (2) are incompatible. Handlers must exist before the inherited metaclass new is called. Therefore, they must be inserted via A: I can keep the signal definitions in the meta class (1), move the handler to the widget (2) and remove (3) B: I can move everything to the widget (I guess!), but define the meta class to overload B hacks into signal discovery, but may be nicer, so I'm giving it a try tomorrow. |
What about something like this:
(any kwargs passed to the signal's call would get forwarded to the handler) |
To avoid breaking compatibility with the existing decorator, we could provide a thunked decorator (e.g. @Inputs.in_data.with_args) or change
This solves just potential thunking, but not passing **kwargs. At first I thought that changing While this is a fun exercise, it's terribly complex --- and this may be about the only widget where it would be used. |
Yeah, I forgot that the only the name of the method is stored as handler, which means that each signal would have to have its own named handler (no lambdas or partials). Another idea (the last one I promise :)) If WidgetManager was modified a bit (line 822)
we would just have to mark the method, and it would be called with the signal as a parameter, which should be sufficient to perform all the logic in a single method |
What about this?
If the handler expects a signal name, it receives it. No flags. |
I removed the meta class. Lists of inputs and outputs are again within the widget. The handler is also again a method. Creation and population of Classes I left @astaric, do you like it better? @ales-erjavec, would you object to sending the signal name to the handler, as proposed in this commit (https://github.com/biolab/orange3/pull/2506/files#diff-436cd70924fc901a93215a371a0f8ed2R820)? Handlers belong to widgets, so there seem to be no reason to hide signal names from them. While this widget may be the only place in Orange where we need it (so far?), supporting this may be useful in extensions or when Orange Canvas is used in different contexts, like physics, with different sets of different-minded widgets. Or does it introduce any problems -- or do you consider it inappropriate for some other reason? |
It would break (in a surprising manner) any existing (or future) definition of
I.e. It breaks the principle of least astonishment. If this is done it would be better adding an explicit flag the way @astaric suggested. I like that widgets define an standard setter API for setting the inputs; i.e |
0903406
to
05414d9
Compare
It's been fun, but @ales-erjavec is right. This is now essentially #2418 + some refactoring and tests. When somebody approves, I'll squash the commits. |
952a4da
to
6f159c6
Compare
6f159c6
to
ac05ad3
Compare
ac05ad3
to
c556d35
Compare
Issue
Alternative to #2418.
Description of changes
Allow multiple inputs, store them in dictionaries and expose them under their existing names (e.g.
in_data
) in case there is only a single signal, and with plural names (e.g.in_datas
) bound to lists of inputs (zero, one or more).Creation of inputs and outputs is automatized through a meta class. The advantage of this is, beside easier adding of new inputs and outputs, sharing the common code for all inputs. For instance, when testing multiple inputs, we only need to test
in_data
(in_datas
) since other inputs work the same way.Includes