News for hackers. Stuff that matters.
Re:Statically-typed error handling in Python using Mypy by dbrgn on Sunday December 08, 2019 @02:34PM (#21737722)
Hi, thanks for featuring my result library!

Regarding your criticism that `result.ok()` returns `None` if the value is not an `Ok` type: That's what `result.unwrap()` and `result.expect(msg)` are for :) (There's no unwrap_err and expect_err so far, but PRs are welcome.) The lib is strongly inspired by Rust (see https://doc.rust-lang.org/std/result/enum.Result.html), that's why `result.ok()` returns something option-ish.

I like your `isinstance` approach btw! Will have to think about it a bit more. Reminds me a bit of Typescript as well. Does mypy have type guards (https://www.typescriptlang.org/docs/handbook/advanced-types....)? Maybe that could be used to create helper functions that check for success/failure and which help mypy to derive the correct type.

Re:Statically-typed error handling in Python using Mypy by uryga on Sunday December 08, 2019 @05:22PM (#21738819)
> Does mypy have type guards?

not yet, maybe in the future. might be possible to emulate some use cases with Literal Types. tracking issue:

https://github.com/python/mypy/issues/5206

Re:Statically-typed error handling in Python using Mypy by karlicoss on Sunday December 08, 2019 @05:31PM (#21738886)
Oh, not sure how I missed these methods, thanks! I'll update the post to reflect it.