Skip to content

Expand to 19 verified Python pitfalls with fixes and runnable examples - #1

Merged
EMRahman merged 1 commit into
mainfrom
docs/expand-pitfalls
Oct 30, 2026
Merged

EMRahman merged 1 commit into
mainfrom
docs/expand-pitfalls

Conversation

@EMRahman

@EMRahman EMRahman commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

Reviews the original seven pitfalls, fixes one incorrect example, adds twelve new ones, and makes the repo easier to browse and find.

Correction

  • #13 Integer caching: c = 257; d = 257; print(c is d) prints True when run as a script, because the compiler merges identical constants in one compilation unit. It only prints False when typed line by line into the REPL. The example now uses int("257") to show the real cache boundary, and the REPL/script difference is documented as its own surprise.

New pitfalls

Category Added
Iterators & laziness zip() truncates and swallows an element from an iterator · generators delay their errors (plus in consuming iterators and empty iterators being truthy, added to #1)
Mutability & aliasing [[0] * 3] * 3 aliasing · shared mutable class attributes
Scope & binding except ... as e deletes e · UnboundLocalError from a line that never runs
Identity & equality True, 1 and 1.0 collide as dict keys
Syntax traps implicit string concatenation · trailing comma makes a tuple
Standard library strip() takes a character set · banker's rounding · return in finally

Structure

  • Pitfalls grouped by category, with a contents table showing the symptom and fix for each.
  • Every entry now has Why and The fix, not just the trap.
  • #7 (list modification) now uses "remove all evens" from [2, 4, 6, 8], which visibly leaves [4, 8].

Verification

  • examples/NN_*.py: one self-checking script per pitfall that asserts the claimed output and the fix.
  • .github/workflows/verify.yml runs every example on CPython 3.10 to 3.14.
  • Added LICENSE (MIT), CONTRIBUTING.md and .gitignore.

Test plan

  • All 19 examples pass locally on CPython 3.13.7 and 3.14
  • CI passes on 3.10 to 3.14

🤖 Generated with Claude Code

- Fix the integer caching example: `c = 257; d = 257; c is d` is True
  in a script (the compiler merges identical constants) and only False
  in the REPL. Use int("257") to show the real behavior.
- Add 12 new pitfalls: zip() truncation and element swallowing, lazy
  generator errors, list multiplication aliasing, shared class
  attributes, deleted exception names, UnboundLocalError, bool/int key
  collisions, implicit string concatenation, trailing-comma tuples,
  strip() character sets, banker's rounding, return in finally.
- Group pitfalls by category, add a contents table, and give every
  entry a "Why" and a "Fix".
- Add a self-checking script per pitfall in examples/ and a CI
  workflow that runs them on CPython 3.10-3.14.
- Add LICENSE (MIT), CONTRIBUTING.md and .gitignore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T12:51:09.497511Z 6c31025 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@EMRahman
EMRahman merged commit e7b7583 into main Oct 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant