Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status Utility Emacs

forthebadge forthebadge forthebadge

raise_if

Python could have raise conditions like 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

def i_must_have_truth(value):
    if not value: raise TypeError('You must give me truth')

So..

$ 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

raise_if(not 1 == 2, TypeError, 'Fails', another_arg='foo')

or

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!

:)

About

one liner `raise Exception if condition` for Python

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages