prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Indentation Issue in ConditionalKeyBindings Example in Documentation

Open
#1,938 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

Hi,

I noticed a potential indentation issue in the documentation for ConditionalKeyBindings:

The bindings = ConditionalKeyBindings(...) line appears to be indented under the is_active() function. This could confuse readers, as it implies the line is part of the function, which would result in it not being executed after the return statement.

Here’s the snippet in question (with the indentation issue):

from prompt_toolkit.key_binding import ConditionalKeyBindings

@Condition
def is_active():
    " Only activate key binding on the second half of each minute. "
    return datetime.datetime.now().second > 30

 bindings = ConditionalKeyBindings(
     key_bindings=my_bindings,
     filter=is_active)

image

This would lead to the bindings = ... line not being executed. I believe the bindings = ... line should be outside the function like this:

@Condition
def is_active():
    "Only activate key binding on the second half of each minute."
    return datetime.datetime.now().second > 30

bindings = ConditionalKeyBindings(
    key_bindings=my_bindings,
    filter=is_active
)

Could you please confirm if this is indeed an error?

Thank you for your hard work on this fantastic library! 🙏

Best,
Joe

Contributor guide

No contributing guide indexed for this repository

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

Open the ConditionalKeyBindings documentation page linked in the issue and inspect the example around the is_active() function. Correct the indentation of the bindings assignment, then verify that the rendered example matches the intended top-level structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.