ruby / gem_rbs_collection

A collection of RBS for gems.
MIT License
246 stars 101 forks source link

Remove Faraday::Utils::Headers#initialize_copy #612

Closed yykamei closed 3 days ago

yykamei commented 4 days ago

Faraday::Utils::Headers inherits Hash and override #initialize_copy.

Previously, #initialize_copy was called in the test file for Faraday to check the type signature, but I noticed the use of this method is marked as an error by Steep. I'm not sure why the current version of Steep reports it, but I decided to remove the declaration from the type signature because #initialize_copy is in the first place a private method originally. In my opinion, it doesn't make sense to expose the signature of #initialize_copy since it cannot be used without #send.

Here is an example code to confirm the method is private.

$ ruby --version
ruby 3.4.0preview1 (2024-05-16 master 9d69619623) [arm64-darwin23]
$
$ ruby <<RUBY

class A < Hash
  def initialize_copy(*)
    super
  end
end

A.new.initialize_copy(A.new)
RUBY
-:8:in '<main>': private method 'initialize_copy' called for an instance of A (NoMethodError)

UPDATE:

As @ksss commented, #initialize_copy is always treated as private from this change. The RBS change is associated with the error report.

github-actions[bot] commented 4 days ago

@yykamei Thanks for your contribution!

Please follow the instructions below for each change. See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.


faraday

You changed RBS files for an existing gem. You can merge this PR yourself because you are a reviewer of this gem. Just comment /merge to merge this PR.

You can also request a review from other reviewers if you want.

ksss commented 3 days ago

Perhaps this change has something to do with it. https://github.com/ruby/rbs/pull/1774 Since rbs 3.5, initialize_copy is automatically treated as private. (This mimics Ruby's behavior.)

yykamei commented 3 days ago

Wow, thank you for sharing such great information. It makes sense to always make the methods , such as #initialize_copy, private. From my perspective, there would be no problems proceeding with the pull request changes because Ruby, as well as RBS, treats #initialize_copy as private. Am I correct?

Anyway, I appreciate your changes on RBS 👍

ksss commented 3 days ago

Yes, LGTM.

yykamei commented 3 days ago

/merge