gluetool.result module

gluetool.result.Error(error)[source]

Shortcut function to create a new error Result.

gluetool.result.Ok(value)[source]

Shortcut function to create a new valid Result.

class gluetool.result.Result(_is_ok, _value, _force=False)[source]

Bases: typing.Generic

A simple Result type inspired by Rust.

A Result can be either Ok(value) - valid result, contains a meaningful value - or Error(error) which represents an error, carrying error’s description.

Parameters:
  • _is_ok (bool) – True when the _value is OK-ish.
  • _value – the value carried by the result.
  • _force (bool) – guards against accidental direct use.
classmethod Error(error)[source]
classmethod Ok(value)[source]
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 31
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of Result

error

Return the result value - error - if it is invalid. Otherwise, None is returned.

expect(message)[source]

Return the result value if it is valid. Otherwise, an exception is raised.

expect_error(message)[source]

Return the result value if it is invalid. Otherwise, an exception is raised.

is_error

Returns True if the result value is invalid.

is_ok
ok

Return the result value - valid - if it is valid. Otherwise, None is returned.

unwrap()[source]

Return the result value if it is valid. Otherwise, an exception is rised.

unwrap_error()[source]

Return the error value if the result is invalid. Othwerise, an exception is raised.

unwrap_or(default)[source]

Return the result value if it is valid. Otherwise, default is returned.

value

Return the result value. It will be either one of valid and error types.