Replies: 1 comment 2 replies
-
https://textual.textualize.io/guide/events/#on-decorator EDIT: I missed this with all the other AI assisted "clarity", but this proposal really just boils down to:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to propose adding optional decorator-based method naming to Textual that would improve developer experience while maintaining full backward compatibility with existing naming conventions.
Problem
While Textual's current naming convention system (e.g.,
on_<message_name>
for message handlers) works well, it creates several developer experience challenges:on_
prefixed names are hard to find and replace consistently@On
decorator not universal: While it works well with messages, it does not provide support foraction_*
orwatch_*
Proposed Solution
Add optional decorators that allow explicit method naming while maintaining the existing convention system:
Benefits
Implementation
The decorators would:
handler_name
property from Message classesExample Implementation (POC)
Here's a proof of concept I've developed, but there are probably some stuffs to improve/change:
Example
Limitations
Static Linting: The decorator approach may occasionally break static linting tools that expect methods to have their final names at definition time. However, this is typically a minor issue as most linting tools work with the runtime method names. The benefits of explicit naming generally outweigh this consideration.
Discussion Reference
This builds on the existing discussion about method naming patterns: #2632
Conclusion
This feature would enhance developer experience without breaking existing code, making Textual applications easier to maintain and refactor while preserving the elegant convention-based approach that makes Textual so powerful. Even if
@on
partially answer this question, it does not seem to work on all textual methods/events (to be confirmed).Note: This proposal has been rephrased with the assistance of AI to ensure clarity and proper technical communication.
Beta Was this translation helpful? Give feedback.
All reactions