• Kirill Smelkov's avatar
    golang, errors, fmt: Error chaining (Python) · 337de0d7
    Kirill Smelkov authored
    Following errors model in Go and fd95c88a (golang, errors, fmt: Error
    chaining (C++/Pyx)) let's add support at Python-level for errors to wrap
    each other and to be inspected/unwrapped:
    
    - an error can additionally provide way to unwrap itself, if it
      provides .Unwrap() method. .__cause__ is not taken into account yet,
      but will be in a follow-up patch;
    - errors.Is(err) tests whether an item in error's chain matches target;
    - `fmt.Errorf("... : %w", ... err)` is similar to `"... : %s" % (..., err)`
      but resulting error, when unwrapped, will return err.
    - errors.Unwrap is not exposed as chaining through both .Unwrap() and
      .__cause__ will need more than just "current element" as unwrapping
      state (i.e. errors.Unwrap API is insufficient - see next patch), and
      in practice users of errors.Unwrap() are very seldom.
    
    Support for error chaining through .__cause__ will follow in the next
    patch.
    
    Top-level documentation is TODO.
    
    See https://blog.golang.org/go1.13-errors for error chaining overview.
    337de0d7
errors_test.py 8.08 KB