opytional

raw JSON →
0.1.0 verified Mon Apr 27 auth: no python

opytional makes working with values that might be None safer and easier. Current version 0.1.0, released about 2020-07-28. Low release cadence.

pip install opytional
error TypeError: unsupported operand type(s) for /: 'int' and 'NoneType'
cause Calling a function without opytionalize that expects a value but receives None.
fix
Apply the @opytionalize decorator to the function to automatically return None when any argument is None.
error AttributeError: module 'opytional' has no attribute 'maybe'
cause Trying to import a non-existent function; opytional only provides opytionalize and a few helpers.
fix
Use 'from opytional import opytionalize' instead.
gotcha opytionalize only works if None is passed as an argument; it does not handle None returned from a called function inside the decorated function.
fix Manually check return values or chain opytionalize on nested calls.
gotcha Library is minimal and not actively maintained; last release 2020, few downloads. Consider using more robust alternatives like pydantic or more-itertools?
fix Evaluate if the library meets your needs; for critical projects, prefer actively maintained alternatives.

Decorator that makes functions return None if any argument is None, avoiding manual None checks.

from opytional import opytionalize

@opytionalize
def maybe_divide(a, b):
    return a / b

result = maybe_divide(10, None)  # returns None instead of raising TypeError