[](https://travis-ci.org/rochacbruno/raise_if)
[](https://coveralls.io/r/rochacbruno/raise_if)


[](http://forthebadge.com)
[](http://forthebadge.com)
[](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
import 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)
[](https://coveralls.io/r/rochacbruno/raise_if)


[](http://forthebadge.com)
[](http://forthebadge.com)
[](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
import 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!
:)
Release files for raise_if 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| raise_if-0.1.4.tar.gz | 2.1 kB | Details |
Release files / raise_if-0.1.4.tar.gz
| Download URL | raise_if-0.1.4.tar.gz |
|---|---|
| Size | 2.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bcaf75a3bdbe1b5cfcb59ddcb98c21074c13132c903fe1d33fed79e0a1bd97e0
|
|
BLAKE2b-256 checksum How to use checksums |
09d0bfa18ae9d9599376d1afa3e0f9c1cf347addf8e49542a4e48d08d52d430b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |