Gratuitous changes to Python exercises

I just checked whether any exercises were out of date, and I saw that there were quite a few changes to the Python exercises. When I looked at what was different, in most cases it was something like this:

class SomeTest:
    def test_something(...):
        ...

changed to this:

class SomeTest:

    def test_something(...):
        ...

This is not only a useless change, but it is also wrong. When I run this through the black formatter, that extra blank line is removed.

PEP-8 says,

Method definitions inside a class are surrounded by a single blank line.

Surrounded, not separated. This means the first method should be proceeded by a blank line. black is one of many formatters, with a strong opinion and limited configuration. It’s not the final arbiter for “right”.

Python tests are auto generated and the tooling is updated from time to time. Formats change. The track is a living, changing, and evolving codebase. Some changes, like updating the Python version, may have wide ranging effects.

4 Likes

Hi @rzuckerm,

@IsaacG is dead on: we recently changed Python versions as well as Black versions.

Interestingly, the Black project had a debate about this very thing, It would appear they landed on the whitespace version somewhere between 2024 and 2025.

When these changes were submitted on the content repo, the CI ran & failed for the following exercise tests, which required that they be regenerated:

Exercise Test Files Failing CI
  • acronym
  • affine-cipher
  • alphametics
  • bob
  • book-store
  • circular-buffer
  • connect
  • diamond
  • difference-of-squares
  • diffie-hellman
  • etl
  • food-chain
  • forth
  • game-of-life
  • go-counting
  • grade-school
  • grains
  • luhn
  • pig-latin
  • pov
  • prime-factors
  • rail-fence-cipher
  • rotational-cipher
  • sgf-parsing
  • swift-scheduling
  • triangle
  • variable-length-quantity

We regenerate tests in an automated fashion for practice exercises and we do not place skips.

Regenerating test files sends the canonical data through JinJa2 and then passes the result through Black before writing out the final file.

Between the Python version change and the Black version change, the process ended up adding in lines for these test files.

Because this was an overall upgrade, we couldn’t use [No important files changed], which unfortunately made this “noisy” for some folx.

4 Likes