dry-python / dry-python/returns

Motivation behind not being able to get IO's content, and IO-wrapped interfacing with unwrapped (normal) code

未关闭
#445 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
4.4k
派生
155
平均合并
2 小时 27 分钟
30 天内合并 PR
22

描述

Hi! Question(s) on `IO`.

I am trying to write a little wrapper for some stateful operation (imagine I have to do IO from/to a file), and I found out that `IO` containers are designed to hide their content. It's impossible to get the value of, say, a successful read result (nothing like `IOSuccess.unwrap()`), unless one uses `unsafe_perform_io`.

What is the rationale behind this design? I am asking because I am not familiar with writing typed functional code, and I could not find a motivation in the documentation for why it shouldn't be possible to get the raw content of an `IO` container.

---

Second question related to interface between IO-wrapped code and normal "unsafe" code:

Let's say I am writing code A where want to mark and wrap all IO operations. Now, code A has to interface with standard python code B. What choices do I have to make them talk?

Do I have to unwrap all my operations with `unsafe_perform_io`, in case I want to do something simple like getting a string from my wrapped code? Do I have to rewrite code B by making it all safe and IO-wrapped, so that they can communicate with no "unsafe" bridge between them?

It seems that in such scenario I would end up with code pieces that are of "different colors" - using the usual async-vs-sync metaphore of incompatible red and blue code -, and I would be forced to make everything of the same color.

(Here "red code" = "python code written in railway style" and "blue code" = "standard procedural python code").

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。