DatalogiForAlle / AgentsPy

Agent-based simulation for education in Python
GNU General Public License v3.0
5 stars 0 forks source link

Allow step/setup functions that doesn't need model-parameter? #104

Open dybber opened 3 years ago

dybber commented 3 years ago

I expect a lot of potential users/students will get this error:

Traceback (most recent call last):
  File "/Users/dpr964/Development/educational/AgentsPy/agents/ui.py", line 562, in <lambda>
    btn.clicked.connect(lambda x: button_spec.function(self.model))
TypeError: step() takes 0 positional arguments but 1 was given
Abort trap: 6

Is it possible to try calling a method, first with the model parameter, and then pass it without it after? I know it's dirty, but in almost all cases the students will not need this parameter

Or should we just try removing it entirely, and see if that makes any problems? Then the setup/step functions should always refer to the global variable (e.g. epidemic_model) and not to the one passed in

JensKanstrupLarsen commented 3 years ago

Something like this?

try:
  btn.clicked.connect(lambda x: button_spec.function(self.model))
except:
  btn.clicked.connect(lambda x: button_spec.function())
dybber commented 3 years ago

Yes, but perhaps be explicit about only catching TypeError's, as we still wants the function to be able to fail with any other type of exception