-
Notifications
You must be signed in to change notification settings - Fork 4
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
handles popping of empty stack #9
base: master
Are you sure you want to change the base?
Conversation
Hi! Thank you for your contribution 👍 If you could look at the comments in your changes, I'll merge it |
@@ -97,10 +95,12 @@ def __draw_line(self, new_c, new_r): | |||
for c in range(self.__channels): | |||
self.array[rr, cc, c] = val * self.__color[c] | |||
|
|||
def stacklen(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be cleaner as a @property
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also prefer a more verbose name, e.g. stack_size
@@ -134,8 +133,10 @@ def push(self): | |||
|
|||
def pop(self): | |||
"""Restore the state that was last pushed. | |||
allow for handling of pops of empty stacks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that by default, this shouldn't be allowed. However, I like the idea of allowing this by setting a boolean keyword argument, so that the method signature becomes something like def pop(self, *, allow_empty=False)
, and when called with .pop(allow_empty=True)
, it would allow the stack to be empty. Otherwise, You could raise a RuntimeError
with a message that the stack is empty and allow_empty
can be used to pop anyway.
@@ -172,4 +173,4 @@ def color(self, c: Color): | |||
if _c < 0 or _c > self.__depth: | |||
raise ValueError('Color value out of range') | |||
|
|||
self.__color = np.array(c, dtype=self.__dtype) | |||
self.__color = np.array(c, dtype=self.__dtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trailing newline has been removed here, could you place it back?
I've started using this for a small class project on evolved L-Systems, and needed a way to elegantly handle popping an empty stack. Hope this helps!