https://github.com/skonik/pretty-match
Pattern matching helpers for your python 3.10 codebase
https://github.com/skonik/pretty-match
match-case pattern-matching python310
Last synced: 4 months ago
JSON representation
Pattern matching helpers for your python 3.10 codebase
- Host: GitHub
- URL: https://github.com/skonik/pretty-match
- Owner: skonik
- License: mit
- Created: 2022-07-15T17:01:01.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-17T20:32:08.000Z (over 3 years ago)
- Last Synced: 2024-04-24T04:43:10.630Z (over 1 year ago)
- Topics: match-case, pattern-matching, python310
- Language: Python
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
🪄 🌟 pretty-match
A set of utils to be used with match-case statements.
```python
from pretty_match import results
from pretty_match.attrs import FirstNoneAttr, AttrIsNone
from pretty_match.comparable import Number
user = User(balance=1500)
product = Product(price=150)
match Number(user.balance).compare(product.price):
case results.Less:
raise NotEnoughMoney
case results.Greater | results.Equal:
process_transaction(user, product)
query = Query(token='test', start=None, end=2)
attrs_to_check = ['token', 'start', 'end']
match FirstNoneAttr(*attrs_to_check, instance=query):
case AttrIsNone(name='token'):
print('token required!')
case AttrIsNone(name='start'):
print('start required!')
case AttrIsNone(name='end'):
print('end required!')
```
## Requirements
* python 3.10
## Development and contribution
Feel free to contribute.
To start development use the following commands:
1. `pre-commit install`
2. `poetry install`
Now you are ready to contribue and develop new feature.
Additional commands:
* `make lint` - run linters and checks;
* `make test` - run tests;