Skip to content

Mutation methods type-locking question #2819

@Strech

Description

@Strech

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 #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions