3 ms·
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.un
by dbrgn 7y ago
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 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.html#type-guards-and-differentiating-types 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.
- uryga 7y ago> 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 https://github.com/python/mypy/issues/5206
- karlicoss 7y agoOh, not sure how I missed these methods, thanks! I'll update the post to reflect it.