Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
raise
as a FunctionRaise exceptions with a function instead of a statement.
Provides a minimal and portable interface for raising exceptions with all the advantages of functions over syntax.
This library's version numbers follow the SemVer 2.0.0 specification <https://semver.org/spec/v2.0.0.html>
_.
::
pip install raise
Import raise_
:
.. code:: python
from raise_ import raise_
Raise an exception:
.. code:: python
raise_(Exception('foo'))
Raise an exception with a traceback:
.. code:: python
raise_(Exception('foo'), traceback)
Raise in a lambda
:
.. code:: python
lambda x: x if x > 0 else raise_(ValueError('x is too small!'))
And of course because raise_
is a function, you can combine
it with functools.partial
and other functional programming
libraries and techniques for many more uses.
raise_
clears __traceback__
if you don't pass in a traceback,
same as if you passed in None
. If you want the Python 3 behavior
of reusing the __traceback__
, you should explicitly pass it in:
.. code:: python
raise_(exception, exception.__traceback__)
Or, if you want to gracefully degrade on Python implementations
which do not have __traceback__
on their exceptions:
.. code:: python
raise_(exception, getattr(exception, '__traceback__', None))
Portable to all releases of both Python 3 and Python 2.
(The oldest tested is 2.5, but it will likely work on all Python 2 versions and probably on even earlier versions.)
For implementations of Python that do not support raising with a custom traceback, a "no traceback" variant is included in the source that can be installed manually.
FAQs
Raise exceptions with a function instead of a statement.
We found that raise demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.