Mutation methods type-locking question

オープン
#2,819 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
ruby
領域
tooling

調査の方向性

この issue で説明されている Hash#transform_values! のシグネチャから始め、ruby/rbs#728 の元の transform_values シグネチャと比較してください。Steep で Net::HTTPResponse の例を再現し、そのミューテーションによって Hash[String, Array[String]] を型エラーなしに Hash[String, String] へ変更できるか確認してください。

索引モデルが issue の本文から書いたものです。

説明

We (at Datadog) stumble upon situation when we use Hash#transform_values! and we get into the trap of type-locking introduced in this PR https://github.com/ruby/rbs/pull/728

What do you think of making both mutation methods have the same signature, like this one (taken from the original transform_values)?

  def transform_values: () -> Enumerator[V, Hash[K, untyped]]
                      | [A] () { (V) -> A } -> Hash[K, A]

Because now there is no way to change the type of say, this expression (response is Net::HTTPResponse)

response.to_hash.transform_values! { |value| Array(value).join }

when run Steep it will complain that original Hash typed as Hash[String, Array[String]] and if something expects to get Hash[String, String] the check will fail, but in fact we mutate the value to be a String.

主要言語
Ruby
スター
2.2k
フォーク
263
平均マージ
1日 20時間
マージ済み PR(30日)
64

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/rbs のほかの issue

ruby/rbs の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。