Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend @on decorator to filter matchable attributes #2498

Merged
merged 27 commits into from
May 8, 2023
Merged

Conversation

rodrigogiraoserrao
Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao commented May 5, 2023

The decorator @on now accepts keyword arguments to provide selectors for attributes that the message has whitelisted in ON_MATCHABLE_ATTRIBUTES.

This will close #2484.

@rodrigogiraoserrao
Copy link
Contributor Author

Tests will pass as soon as I merge #2490.

@rodrigogiraoserrao rodrigogiraoserrao marked this pull request as ready for review May 8, 2023 10:28
Copy link
Contributor Author

@rodrigogiraoserrao rodrigogiraoserrao May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willmcgugan still trying to strike a balance between my personal verbose style and the intended style for the docs.
Let me know how this looks.

Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dead code in the example is a blocker. Either we come up with a working example, or we don't bother with an example for this.

docs/examples/events/on_decorator03.py Outdated Show resolved Hide resolved
docs/examples/events/on_decorator03.py Outdated Show resolved Hide resolved
src/textual/_on.py Outdated Show resolved Hide resolved
docs/guide/events.md Outdated Show resolved Hide resolved
src/textual/message_pump.py Outdated Show resolved Hide resolved
rodrigogiraoserrao and others added 2 commits May 8, 2023 13:25
Co-authored-by: Will McGugan <[email protected]>
Co-authored-by: Will McGugan <[email protected]>
@rodrigogiraoserrao rodrigogiraoserrao changed the title Extend @on decorator to filter arbitrary attributes Extend @on decorator to filter matchable attributes May 8, 2023
@rodrigogiraoserrao
Copy link
Contributor Author

Changed the API so that now the **kwargs can only match attributes that have been whitelisted in the message's ON_MATCHABLE_ATTRIBUTES classvar.

src/textual/message_pump.py Outdated Show resolved Hide resolved
src/textual/message_pump.py Outdated Show resolved Hide resolved
src/textual/message.py Outdated Show resolved Hide resolved
docs/guide/events.md Outdated Show resolved Hide resolved
src/textual/_on.py Outdated Show resolved Hide resolved
src/textual/_on.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor Author

@rodrigogiraoserrao rodrigogiraoserrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@willmcgugan willmcgugan merged commit 855c90d into main May 8, 2023
@willmcgugan willmcgugan deleted the on-kwargs branch May 8, 2023 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend decorator on to specify non-control attributes to match.
2 participants