Allow more complex patterns (without context)
See original GitHub issueAt Python Brasil, we talked a lot about how Pattern obj is so limited and how we could improve it. The main point of the discussion was how we could implement other “types” of patterns:
patterns = [
# 1)
Pattern('ping', ping),
RegexPattern(r'^ping \d*$', regex_ping), # "ping 123" would be accepted
StartswithPattern('/ping', regex_ping), # "/ping bottery" would be accepted
# 2) or
Pattern('ping', ping),
Pattern(r'^ping$', regex_ping, type='regex'),
Pattern('/ping', regex_ping, type='startswidth'),
# 3) or
Pattern('ping', ping),
Pattern(r'^ping$', regex_ping, validator=regex_validator),
Pattern('/ping', regex_ping, validator=startswith_validator),
# where regex_validator and startswith_validator are the checkers
]
I believe the second “kind of” pattern is the easiest for who will use Bottery. But I think we should discuss it better.
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
Reshaping Context Patterns - Quantum Leaders
Learning to reshape Context patterns becomes a critical skill for both ... we are young to handling more complex situations as we mature....
Read more >A Leader's Framework for Decision Making
Complicated contexts, unlike simple ones, may contain multiple right answers, and though there is a clear relationship between cause and effect, not everyone ......
Read more >What's in a Context? Cautions, limitations, and potential paths ...
Secondly, context in this paradigm is complex, involving multiple dimensions in the environment (e.g., color, texture, pattern), as well as ...
Read more >Making sense of complexity in context and implementation ...
Complex interventions usually comprise multiple components, which may act independently or interdependently, with the 'active ingredient(s)' ...
Read more >Content filtering in Amazon EventBridge event patterns
Amazon EventBridge supports declarative content filtering using event patterns. With content filtering, you can write complex event patterns that only match ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think I prefer the first option. This would give us more flexibility for extra attributes depending on the pattern class; for instance, it’d make sense for RegexPattern to be able to use named groups, but that would make zero sense for Pattern. It’d be easier for IDEs to show some hints based on the pattern class
Even though 2 could potentially be easier to implement, on the long run it could increase complexity.
Although I think that the second (2) option seems as an easier way to remember things, I personally prefer the first one.
I think the first option would be easier to remember, easier to document and generates lines with less characters, which makes it more readable. Also, you can explore and individualize each of the patterns very well, which seems easier for me.