Fixed a crash when step option is missing#2261
Conversation
There has been a weird branching.
|
Hi @StSav012 thanks for the PR! This LGTM.
Given that it's a dictionary, and python dictionaries are mutable, yeah we should definitely assume it's mutable. @ixjlyons you going to be able to look at this? if not, this looks ok to merge (would have to look at |
|
Hi, @j9ac9k
I thought of returning a copy of |
|
I'm not opposed to something like this, but likely care would have to be taken to ensure we don't break stuff for existing users. Also, I'm not sure if this has come up in the issue tracker yet either. |
ixjlyons
left a comment
There was a problem hiding this comment.
Looks fine to me, though it's probably also worth fixing up the doc string to note that the default step is 1 in "int mode" and that it's rounded.
This pattern is pretty common across the library, so it probably deserves a separate discussion/issue. I'm almost sure there are people relying on |
It's not actually so. I haven't figured out how to make it really a default value. Therefore, I don't understand whether As for the docstrings, I altered the ones I found. As a side note, I have a temptation to fix a bizarre code of if 'minStep' in opts:
step = opts['minStep']
if int(step) != step:
raise Exception('Integer SpinBox must have integer minStep size.')
else:
ms = int(self.opts.get('minStep', 1))
if ms < 1:
ms = 1
self.opts['minStep'] = msThe code after |
Ah, right. It's if kwargs.get("int", False):
self.opts["step"] = 1It's not that important from a behavior standpoint, but it is a little odd that
The only thing I can think of is dynamically toggling int mode: The proposed change would make it 1 instead. There might be other subtle ways toggling int mode on/off breaks things anyway, so I don't know if it's worth handling it. I'm inclined to leave it though. |
|
Dear @ixjlyons The code I'm pointing at is fired when if 'minStep' in opts:
step = opts['minStep']
if int(step) != step:
raise Exception('Integer SpinBox must have integer minStep size.')
else:
ms = int(self.opts.get('minStep', 1))
if ms < 1:
ms = 1
self.opts['minStep'] = msThe change I propose now is if 'minStep' in opts:
step = opts['minStep']
if int(step) != step:
raise Exception('Integer SpinBox must have integer minStep size.')
else:
self.opts['minStep'] = 1 # the code reduces to this single lineHere's the code that triggers the block after sb = pg.SpinBox(int=False, minStep=5)
print(f"{'minStep' in sb.opts = }") # True
del sb.opts["minStep"] # yes, delete
print(f"{'minStep' in sb.opts = }") # False
sb.setOpts(int=True) # here, the else part works
print(f'{sb.opts["minStep"] = }') # 1In the original code, if 'minStep' in opts:
step = opts['minStep']
if int(step) != step:
raise Exception('Integer SpinBox must have integer minStep size.')
ms = int(self.opts.get('minStep', 1))
if ms < 1:
ms = 1
self.opts['minStep'] = msThe check that |
ixjlyons
left a comment
There was a problem hiding this comment.
Sorry for letting this sit for so long. The changes as they are now look good to me.
@StSav012, I see now I had overlooked self.opts being populated at the top of setOpts before getting to the "sanity checks" section. If you're still interested proposing further cleanup, it might be best to do so in a follow-up pull request.
Thanks for reviewing @ixjlyons and thanks for your submission @StSav012 merging! Belay that, just saw the CI failures pretty sure they're unrelated but I'm going to verify. |
|
Going to close/reopen this PR to trigger a new CI Run since I can't seem to figure out how to do it on the CI page 😬 |
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
* Fixed crash when `step` option is missing There has been a weird branching. * Updated docstrings * Made 'step' 1 by default if 'int' is True pyqtgraph#2261 (comment)
This reverts commit 338a72c.
There has been a weird branching.
As a side note, should
self.optsbe mutable? It doesn't look safe.