Skip to content

Indentation Issue in ConditionalKeyBindings Example in Documentation #1938

@joem76

Description

@joem76

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions