# Buggy code
def paint_stakes(emitter, stakes, paint_inactive: bool = False):
    header = (
        f"| ~ | Staker | Worker | # | Value    | Duration     | Enactment          "
    )
    breaky = f"|   | ------ | ------ | - | -------- | ------------ | ----------------------------------------- "

    active_stakes = sorted(
        (stake for stake in stakes if stake.is_active),
        key=lambda some_stake: some_stake.address_index_ordering_key,
    )
    if active_stakes:
        title = "======================================= Active Stakes =========================================\n"
        emitter.echo(title)
        emitter.echo(header, bold=True)
        emitter.echo(breaky, bold=True)

        for index, stake in enumerate(active_stakes):
            row = prettify_stake(stake=stake, index=index)
            row_color = (
                "yellow"
                if stake.worker_address == BlockchainInterface.NULL_ADDRESS
                else "white"
            )
            emitter.echo(row, color=row_color)
        emitter.echo("")  # newline

    if paint_inactive:
        title = "\n====================================== Inactive Stakes ========================================\n"
        emitter.echo(title)
        emitter.echo(header, bold=True)
        emitter.echo(breaky, bold=True)

        for stake in sorted(
            [s for s in stakes if s not in active_stakes],
            key=lambda some_stake: some_stake.address_index_ordering_key,
        ):
            row = prettify_stake(stake=stake, index=None)
            emitter.echo(row, color="red")
        emitter.echo("")  # newline
    elif not active_stakes:
        emitter.echo(f"There are no active stakes\n")


# Traceback (AttributeError)
____    __            __
/\  _`\ /\ \__        /\ \
\ \,\L\_\ \ ,_\    __ \ \ \/'\      __   _ __
\/_\__ \\ \ \/  /'__`\\ \ , <    /'__`\/\`'__\
/\ \L\ \ \ \_/\ \L\.\\ \ \\`\ /\  __/\ \ \/
\ `\____\ \__\ \__/.\_\ \_\ \_\ \____\\ \_\
\/_____/\/__/\/__/\/_/\/_/\/_/\/____/ \/_/

The Holder of Stakes.

======================================= Active Stakes =========================================

| ~ | Staker | Worker | # | Value    | Duration     | Enactment
|   | ------ | ------ | - | -------- | ------------ | -----------------------------------------
| 0 | 0xFD3D | 0x1368 | 0 | 15000 NU | 45 periods . | Aug 06 21:00:30 PDT - Sep 20 21:00:30 PDT
| 1 | 0xFD3D | 0x1368 | 1 | 100000 NU | 300 periods  | Oct 01 21:00:30 PDT - Jul 27 21:00:30 PDT
| 2 | 0x9CA6 | 0x3d51 | 0 | 175864.607570726413344034 NU | 33 periods . | Aug 25 21:00:30 PDT - Sep 27 21:00:30 PDT
| 3 | 0x9CA6 | 0x3d51 | 1 | 200000 NU | 365 periods  | Oct 01 21:00:30 PDT - Sep 30 21:00:30 PDT
| 4 | 0x26FD | 0x4801 | 0 | 50000 NU | 60 periods . | Sep 01 21:00:30 PDT - Oct 31 21:00:30 PDT

Select Stake: 4
Enter target value (must be less than or equal to 50000 NU): 40000
Enter number of periods to extend: 250
Traceback (most recent call last):
File "/home/michwill/.local/share/virtualenvs/nucypher-kms-5SSQ9ZHE/bin/nucypher", line 11, in <module>
load_entry_point('nucypher', 'console_scripts', 'nucypher')()
File "/home/michwill/.local/share/virtualenvs/nucypher-kms-5SSQ9ZHE/lib/python3.7/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/michwill/.local/share/virtualenvs/nucypher-kms-5SSQ9ZHE/lib/python3.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/michwill/.local/share/virtualenvs/nucypher-kms-5SSQ9ZHE/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/michwill/.local/share/virtualenvs/nucypher-kms-5SSQ9ZHE/lib/python3.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/michwill/.local/share/virtualenvs/nucypher-kms-5SSQ9ZHE/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/michwill/.local/share/virtualenvs/nucypher-kms-5SSQ9ZHE/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/michwill/.local/share/virtualenvs/nucypher-kms-5SSQ9ZHE/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/michwill/Projects/nucypher-kms/nucypher/cli/config.py", line 217, in wrapper
return func(config, *args, **kwargs)
File "/home/michwill/Projects/nucypher-kms/nucypher/cli/characters/stake.py", line 365, in stake
extension=extension)
File "/home/michwill/Projects/nucypher-kms/nucypher/cli/painting.py", line 406, in paint_staged_stake_division
new_end_period = original_stake.end_period + extension
AttributeError: 'Stake' object has no attribute 'end_period'
Sentry is attempting to send 0 pending error messages
Waiting up to 2.0 seconds
Press Ctrl-C to quit

# Fixed code
def paint_stakes(emitter, stakes, paint_inactive: bool = False):
    header = (
        f"| ~ | Staker | Worker | # | Value    | Duration     | Enactment          "
    )
    breaky = f"|   | ------ | ------ | - | -------- | ------------ | ----------------------------------------- "

    active_stakes = sorted(
        (stake for stake in stakes if stake.is_active),
        key=lambda some_stake: some_stake.address_index_ordering_key,
    )
    if active_stakes:
        title = "======================================= Active Stakes =========================================\n"
        emitter.echo(title)
        emitter.echo(header, bold=True)
        emitter.echo(breaky, bold=True)

        for index, stake in enumerate(active_stakes):
            row = prettify_stake(stake=stake, index=index)
            row_color = (
                "yellow"
                if stake.worker_address == BlockchainInterface.NULL_ADDRESS
                else "white"
            )
            emitter.echo(row, color=row_color)
        emitter.echo("")  # newline

    if paint_inactive:
        title = "\n====================================== Inactive Stakes ========================================\n"
        emitter.echo(title)
        emitter.echo(header, bold=True)
        emitter.echo(breaky, bold=True)

        for stake in sorted(
            [s for s in stakes if s not in active_stakes],  # TODO
            key=lambda some_stake: some_stake.address_index_ordering_key,
        ):
            row = prettify_stake(stake=stake, index=None)
            emitter.echo(row, color="red")

        emitter.echo("")  # newline
    elif not active_stakes:
        emitter.echo(f"There are no active stakes\n")