Probably the small python package, only includes raise_if function
Project description
[![Build
Status](https://travis-ci.org/rochacbruno/raise_if.png)](https://travis-ci.org/rochacbruno/raise_if)
[![Coverage
Status](https://coveralls.io/repos/rochacbruno/raise_if/badge.png)](https://coveralls.io/r/rochacbruno/raise_if)
[![Code Health](https://landscape.io/github/rochacbruno/raise_if/master/landscape.svg)](https://landscape.io/github/rochacbruno/raise_if/master)
![Utility](https://img.shields.io/badge/utility-0%25-lightgrey.svg)
![Emacs](https://img.shields.io/badge/built%20with-EMACs-blue.svg)
[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com)
[![forthebadge](http://forthebadge.com/images/badges/gluten-free.svg)](http://forthebadge.com)
[![forthebadge](http://forthebadge.com/images/badges/built-by-developers.svg)](http://forthebadge.com)
# raise_if
Python could have raise conditions like Ruby.
```ruby
def i_must_have_truth(value)
raise TypeError, 'You must give me truth' if value == false
end
```
But the only one line option that works hurts PEP8
```python
def i_must_have_truth(value):
if not value: raise TypeError('You must give me truth')
```
So..
```python
$ pip install raise_if
def i_must_have_truth(value):
raise_if(not value, TypeError, 'You must give me truth')
```
Pass exception type and arguments
```python
raise_if(not 1 == 2, TypeError, 'Fails', another_arg='foo')
```
or
```python
raise_if(not 1 == 2, TypeError('Fails', another_arg='foo'))
```
Why??
Because I am lazy and I do not like extra breaks in a chain of if statements!
:)
Status](https://travis-ci.org/rochacbruno/raise_if.png)](https://travis-ci.org/rochacbruno/raise_if)
[![Coverage
Status](https://coveralls.io/repos/rochacbruno/raise_if/badge.png)](https://coveralls.io/r/rochacbruno/raise_if)
[![Code Health](https://landscape.io/github/rochacbruno/raise_if/master/landscape.svg)](https://landscape.io/github/rochacbruno/raise_if/master)
![Utility](https://img.shields.io/badge/utility-0%25-lightgrey.svg)
![Emacs](https://img.shields.io/badge/built%20with-EMACs-blue.svg)
[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com)
[![forthebadge](http://forthebadge.com/images/badges/gluten-free.svg)](http://forthebadge.com)
[![forthebadge](http://forthebadge.com/images/badges/built-by-developers.svg)](http://forthebadge.com)
# raise_if
Python could have raise conditions like Ruby.
```ruby
def i_must_have_truth(value)
raise TypeError, 'You must give me truth' if value == false
end
```
But the only one line option that works hurts PEP8
```python
def i_must_have_truth(value):
if not value: raise TypeError('You must give me truth')
```
So..
```python
$ pip install raise_if
def i_must_have_truth(value):
raise_if(not value, TypeError, 'You must give me truth')
```
Pass exception type and arguments
```python
raise_if(not 1 == 2, TypeError, 'Fails', another_arg='foo')
```
or
```python
raise_if(not 1 == 2, TypeError('Fails', another_arg='foo'))
```
Why??
Because I am lazy and I do not like extra breaks in a chain of if statements!
:)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
raise_if-0.1.1.tar.gz
(1.8 kB
view details)
File details
Details for the file raise_if-0.1.1.tar.gz
.
File metadata
- Download URL: raise_if-0.1.1.tar.gz
- Upload date:
- Size: 1.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be750bfbba62c1473028f40c5459c8d64491a6ad45b1e2ff437006a6f1299679 |
|
MD5 | d3a645e5d7ebaf62f35275d8f90e0834 |
|
BLAKE2b-256 | 3bb66bdc7eaf00f776d3f7707e7641447b11cfba81c956fba50b0e80f7472765 |