bbangert/zilch — pull request #2 by mgedmin (2012-01-02 19:59:35+00:00)
Title: Bugfix for code context in tracebacks (one line of code was not shown)

Here's why this change makes sense:

* frame.get('with_context') is something like 'a1\na2\na3\na4\na5\nc\nb1\nb2\nb3\nb4\n'

* when you split it by '\n' you get ['a1', 'a2', 'a3', 'a4', 'a5', 'c', 'b1', 'b2', 'b3', 'b4', 'b5', ''] -- note the extra '' at the end!

* to get the three preceding lines, take [:5] to get ['a1', 'a2', 'a3', 'a4', 'a5'], then [-3:] to get ['a3', 'a4', 'a5'] -- everything is fine

* to get the three succeeding lines, you can't take [-5:] -- that gives you ['b2', 'b3', 'b4', 'b5', '']!

* [-6:] would work but it looks weirdly asymmetric after the [:5].

* I chose [6:], because it nicely splits the list of lines into three parts: above context ([:5]), context ([5:6]), and below context ([6:]) -- except we use frame.get('context_line') instead of extracting the middle [5:6] part by hand.