# Dis.py: STACK.append vs STACK.push

**URL:** <https://discuss.python.org/t/dis-py-stack-append-vs-stack-push/45330>\
**Category:** Documentation\
**Created:** [February 8, 2024, 12:30am UTC](https://discuss.python.org/t/dis-py-stack-append-vs-stack-push/45330 "2024-02-08T00:30:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smontanaro](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/smontanaro/32/1389_2.png) [@smontanaro](https://discuss.python.org/u/smontanaro)\
**Post date:** [February 8, 2024, 12:30am UTC](https://discuss.python.org/t/dis-py-stack-append-vs-stack-push/45330/1 "2024-02-08T00:30:07Z")

</div>

I need to practice my backport cherry picking (and corresponding pull requesting). I have a simple case in mind. Stack operation activity described in the file `library/dis.rst` mentions both `STACK.append` and `STACK.push` as the inverse of `STACK.pop`. I’m old-fashioned and prefer `push` to `append`, but if the concensus is to use `append`, I’ll change `push` to `append`. Looking at `git blame` output, I see both @markshannon and @MatthieuDartiailh associated with the relevant lines.

This is just an exercise in improving my `git fu`. I’m happy to do some more activity in `dis.rst`, but for the moment just want to generate a PR I know will hiccup when `bedevere` attempts the automatic backport. Some changes would are associated with 3.12, so would fail to apply cleanly to 3.11.

---

<div class="post-metadata">

**Author:** ![tjreedy](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tjreedy/32/137_2.png) [@tjreedy](https://discuss.python.org/u/tjreedy)\
**Post date:** [February 12, 2024, 2:41am UTC](https://discuss.python.org/t/dis-py-stack-append-vs-stack-push/45330/2 "2024-02-12T02:41:08Z")

</div>

I oppose both the change and the reason given for doing it. When you have a real need for a non-auto backport, I would be willing to help.

---

<div class="post-metadata">

**Author:** ![nedbat](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nedbat/32/8744_2.png) [@nedbat](https://discuss.python.org/u/nedbat)\
**Post date:** [February 12, 2024, 1:40pm UTC](https://discuss.python.org/t/dis-py-stack-append-vs-stack-push/45330/3 "2024-02-12T13:40:46Z")

</div>

I think it makes sense to use just one term for the operation. STACK is introduced with:

> In the following, We will refer to the interpreter stack as `STACK` and describe  
> operations on it as if it was a Python list.

so `.append` makes sense to me, though I could see using `.push` if it’s explained at the beginning. Make the PR, I’m sure you’ll get help working it through.

---

<div class="post-metadata">

**Author:** ![smontanaro](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/smontanaro/32/1389_2.png) [@smontanaro](https://discuss.python.org/u/smontanaro)\
**Post date:** [February 12, 2024, 1:46pm UTC](https://discuss.python.org/t/dis-py-stack-append-vs-stack-push/45330/4 "2024-02-12T13:46:28Z")

</div>

Fine, you want lists, then maybe `STACK.push` should be changed to `STACK.append`?

You’re letting implementation details bleed into user-facing documentation. If it’s conceptually a stack, then use typical stack nomenclature to describe it.

---

<div class="post-metadata">

**Author:** ![nedbat](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nedbat/32/8744_2.png) [@nedbat](https://discuss.python.org/u/nedbat)\
**Post date:** [February 12, 2024, 2:07pm UTC](https://discuss.python.org/t/dis-py-stack-append-vs-stack-push/45330/5 "2024-02-12T14:07:42Z")

</div>

> [@nedbat](#):
>
> describe operations on it as if it was a Python list.

I’m simply pointing out that there’s already a statement at the top of the page explaining how STACK is being used. It’s not leaking implementation details because the stack is not actually a Python list. It’s being described on this page in terms familiar to the readers (that is, Python programmers).

---

<div class="post-metadata">

**Author:** ![tjreedy](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tjreedy/32/137_2.png) [@tjreedy](https://discuss.python.org/u/tjreedy)\
**Post date:** [February 13, 2024, 6:32am UTC](https://discuss.python.org/t/dis-py-stack-append-vs-stack-push/45330/6 "2024-02-13T06:32:31Z")

</div>

> [@smontanaro](#):
>
> If it’s conceptually a stack

As I explained on the issue and PR, STACK is not a ‘stack’ as usually defined as the code examples also perform non-stack operations (indexing and slicing). Also, as far as I looked, the code examples are executable Python code and STACK.push() is not.

25 years ago, when I proposed the addition of list.pop, I pointed out that if one were using a list \_ _as a stack_, one could define `push = _.append` and `pop = _.pop` and thereafter use `push` and `pop` (or the same with prefixes or suffixes added). That approach is not applicable to STACK precisely because it is _not_ just used as a stack. I suppose one could define the concept “indexable stack”

---

<div class="post-metadata">

**Author:** ![nedbat](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nedbat/32/8744_2.png) [@nedbat](https://discuss.python.org/u/nedbat)\
**Post date:** [February 13, 2024, 11:54pm UTC](https://discuss.python.org/t/dis-py-stack-append-vs-stack-push/45330/7 "2024-02-13T23:54:24Z")

</div>

I’ve created [docs: use consistent .append() in dis.rst by nedbat · Pull Request #115434 · python/cpython · GitHub](https://github.com/python/cpython/pull/115434) to use `.append()` throughout.
