Skip to content
DevMeme
2390 of 7435
Append Says Two Arguments Given
Bugs Post #2657, on Jan 22, 2021 in TG

Append Says Two Arguments Given

Why is this Bugs meme funny?

Level 1: Put It In A Box

Imagine a shelf worker says, "Give me one box to put on the shelf." You hand them two loose toys, and they get confused. If you put both toys inside one box first, everything works. The meme is funny because the computer's complaint sounds like nonsense, even though the real issue is that the two values needed to be packed together as one thing.

Level 2: One Thing Means One

append is a method used to add something to the end of a list. The important word is "something": one object. That object can be simple, like a number, or compound, like a tuple containing two values.

So this call passes two separate arguments:

fragments.append(x, y)

But this call passes one argument that contains two values:

fragments.append((x, y))

That extra set of parentheses changes the meaning. It tells Python, "treat x and y as one pair." Without it, Python sees two separate things and complains that append was not designed for that call.

For newer developers, this is a common RuntimeErrors lesson: an error message can be technically related to the problem without explaining the programmer's intent. The cartoon character's blank stare works because the text looks self-contradictory, but the underlying fix is about understanding the method's contract.

Level 3: Arity Gaslighting

The image puts the whole frustration in one pink error strip:

fragments.append(x,y)

TypeError: append() takes 2 arguments (2 given)

The joke is that the error message appears to pass its own math test. It says the function takes 2 arguments and that 2 were given, so the wide-eyed cartoon developer underneath has exactly the right expression: then what do you want from me?

The real Python gotcha being pointed at is usually arity: how many arguments a function or method accepts. For a normal list, append accepts one item to add to the list. If you call fragments.append(x, y), you are not saying "append the pair x and y"; you are saying "call append with two separate arguments." Python's list API does not treat those as a bundle just because they look related.

The likely intended code is one of these:

fragments.append((x, y))      # append one tuple containing two values
fragments.extend([x, y])      # append two separate values to the list

Those are different data-structure choices. append((x, y)) produces a list of coordinate-like pairs, while extend([x, y]) flattens the values into the list. The difference matters later when code expects each element of fragments to be a fragment object, coordinate tuple, token, or whatever this poor variable was supposed to contain before the stack trace began negotiations.

The meme's diagnostic wording is also part of the pain. Real ErrorMessages often compress several layers of language implementation into one sentence: implicit receiver objects, bound methods, positional arguments, and API-specific calling conventions. A method call like object.method(value) can involve an object being supplied behind the scenes, while the programmer only sees the arguments inside the parentheses. That is why argument-count errors can feel like they are written by someone who technically knows the truth and has chosen not to be helpful about it.

This is a small LanguageGotcha, but it scales into real Debugging time because the code looks semantically obvious. Developers often think in domain units: "add this x/y point," "add this key/value pair," "add this start/end range." Python thinks in function signatures: one positional item means one positional item. If the item itself contains two values, wrap it in a tuple, list, dataclass, or small object. The runtime is not going to infer your data model from your hopes. It has meetings to avoid too.

Description

The top of the meme shows a pink-highlighted code/error strip with `fragments.append(x,y)` and the message "TypeError: append() takes 2 arguments (2 given)." Below it is a wide-eyed cartoon character at a computer, wearing an orange mask and a shirt that says "Yes." The humor comes from the error appearing to complain even though the displayed count says the expected and supplied argument totals match. In practical Python terms, it points at the familiar confusion around `append` taking one item, so a coordinate pair should usually be passed as a tuple like `append((x, y))` rather than as two separate arguments.

Comments

4
Anonymous ★ Top Pick Nothing says dynamic language ergonomics like an arity error that passes its own equality check.
  1. Anonymous ★ Top Pick

    Nothing says dynamic language ergonomics like an arity error that passes its own equality check.

  2. @Arilas 5y

    IndexOutOfRangeException: Invalid kernelIndex (0) passed, must be non-negative less than 0. Unity

  3. @anysound 5y

    Does builtin exceptions really have this bug with methods?

  4. Deleted Account 5y

    😆😆🤣🤣

Use J and K for navigation