-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Limit recursion in reprs to avoid stack overflow for circular references #396
Comments
Additional ContextIt's no problem with only one $ python 'test_issue_multple_param_action.py'
(.venv) Codeimport param
class InputDataComponent(param.Parameterized):
update_data = param.Action()
# download_data = param.Action()
def __init__(self, **params):
super().__init__(**params)
self.update_data = self._update_data
# self.download_data = self._download_data
def _update_data(self, event):
raise NotImplementedError()
def _download_data(self, event):
raise NotImplementedError()
repr(InputDataComponent()) |
WorkaroundSetting the Thanks to @jbednar $ python 'test_issue_multple_param_action.py'
(.venv) import param
class InputDataComponent(param.Parameterized):
update_data = param.Action()
download_data = param.Action()
def __init__(self, **params):
super().__init__(**params)
self.update_data = self._update_data
# self.download_data = self._download_data
def _update_data(self, event):
raise NotImplementedError()
def _download_data(self, event):
raise NotImplementedError()
def __repr__(self):
return f"InputDataComponent(name='{self.name}')"
repr(InputDataComponent()) |
xref #209 |
@MarcSkovMadsen sorry, unrelated question! When I click to open a new issue on a holoviz repo (including param), I get the view below, and then the issue is created with labels like "triage" and "bug" (depending which option I pick): Meanwhile, your issue is somehow without that stuff. We've been trying to improve all this stuff across holoviz, having org-wide templates and so forth - but seems like we haven't done something right somewhere... |
Ok, this issue should now be about a request to add proper limits on the levels of recursion to which we expand Parameterized objects in reprs. I vote for two levels, so that printing a Parameterized prints its parameter values (which may themselves be Parameters), but does not print the parameter values of the Parameterized subobjects: Three levels is a bit more informative but to me seems likely to be more overwhelming than useful (though it's not a strong preference for 2): Beyond that seems like overkill to me... |
The real problem seems to be infinite recursion, i.e. two Parameterizeds that are nested and reference each other. Ideally we should make sure that a Parameterized should not appear more then once in the repr and indicate the recursion through some abbreviation. Not saying we shouldn't also limit the depth of the repr but it doesn't seem like the real root of the issue. |
Sure, the serious problem is infinite recursion, but it seems like we can easily avoid it rather than solving it. Solving it would seem to require keeping a list of |
Doesn't seem at all straightforward to me, the simple case of a Parameter that holds a Parameterized is of course, but even in this example that wasn't the issue. Here the |
Good point. Yes, that's annoying. |
It looks like the repr in this case should be:
(where ... refers to itself). I don't suppose there's any way to control the repr of a bound method. I guess Parameterized's repr could check for a value that's a bound method of self, but that wouldn't catch a reference to something that points back to this object. |
Just for info. I just experienced this again in another use case. I can live with it now that I know the cause and a workaround. But I think it could be annoying for a lot of other users. |
Justed wasted 30 minutes on debugging strange stack overflow when testing with Pytest before I released it was due to this again. I get no indication that this is the error. But happens often when I have two or more |
We should try this https://twitter.com/raymondh/status/1276571193710047232?s=19 |
@mccav experiences this problem. See https://discourse.holoviz.org/t/how-do-i-use-param-action-in-panel/923/5?u=marc and also this https://discourse.holoviz.org/t/how-do-i-use-param-action-in-panel/923/6?u=marc |
This is another reason to drop Python 2 soon (and use that decorator, assuming it works for our purposes). |
Fixed in #499. |
System Info
My Pain
I'm developing a component based on
Param
andPanel
and would like to test it withpytest
. During development my tests stopped working/ running but without errors. After some debugging I discovered it was due to a stackoverflow that pytest did not report. It just stopped.I've developed a smaller code example below. I've also included the stack trace.
Stack Trace
Code
The text was updated successfully, but these errors were encountered: