python / python/cpython

Discrepancy between inplace add and add for list and iterables

Open
#96,770 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Documentation

Noticed this discrepancy between inplace add and add for list and iterables, not sure if this behavior is purposefully intended or a bug:

The Addition Assignment += operator will concatenate str to list, treating the str as an iterable and behaving like list.extend(...) instead of throwing TypeError, as one might expect, since the Addition operator + throws a TypeError when attempting to concatenate str to list.

code snippet

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the attached examples comparing list += with list + for strings and other iterables, then read the relevant Python language documentation for these operators. Done means the discrepancy's intended behavior is established and the appropriate documentation change or clarification is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.