Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable typing in a few more files #14937

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Cask
Expand Down
7 changes: 7 additions & 0 deletions Library/Homebrew/cask/metdata.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# typed: strict

module Cask
module Metadata
requires_ancestor { Cask }
end
end
1 change: 0 additions & 1 deletion Library/Homebrew/cask/url.rbi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# typed: strict
# typed: false

class URL
include Kernel
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/bump-formula-pr.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "formula"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/bump-unversioned-casks.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "timeout"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/irb.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "formulary"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/pr-automerge.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "cli/parser"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/pr-upload.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "cli/parser"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/prof.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "cli/parser"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "cli/parser"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "cli/parser"
Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "keg"
Expand Down Expand Up @@ -31,7 +31,7 @@ def self.missing_deps(formulae, hide = nil)

def self.checks(type, fatal: true)
@checks ||= Checks.new
failed = false
failed = T.let(false, T::Boolean)
@checks.public_send(type).each do |check|
out = @checks.public_send(check)
next if out.nil?
Expand Down Expand Up @@ -64,6 +64,7 @@ def find_relative_paths(*relative_paths)
end
end

sig { params(list: T::Array[String], string: String).returns(String) }
def inject_file_list(list, string)
list.reduce(string.dup) { |acc, elem| acc << " #{elem}\n" }
.freeze
Expand Down Expand Up @@ -642,10 +643,11 @@ def check_deprecated_disabled
EOS
end

sig { returns(T.nilable(String)) }
def check_git_status
return unless Utils::Git.available?

message = nil
message = T.let(nil, T.nilable(String))

repos = {
"Homebrew/brew" => HOMEBREW_REPOSITORY,
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/extend/os/mac/extend/ENV/std.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Stdenv
Expand All @@ -7,7 +7,7 @@ module Stdenv
undef homebrew_extra_pkg_config_paths

def homebrew_extra_pkg_config_paths
["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"]
[Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")]
end

def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/extend/os/mac/extend/ENV/super.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Superenv
Expand Down Expand Up @@ -29,7 +29,7 @@ def bin

# @private
def homebrew_extra_pkg_config_paths
["/usr/lib/pkgconfig", "#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"]
[Pathname("/usr/lib/pkgconfig"), Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")]
end

# @private
Expand Down Expand Up @@ -68,7 +68,7 @@ def homebrew_extra_cmake_include_paths
end

def homebrew_extra_cmake_library_paths
["#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"]
[Pathname("#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries")]
end

def homebrew_extra_cmake_frameworks_paths
Expand Down Expand Up @@ -96,7 +96,7 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a
end

self["HOMEBREW_DEVELOPER_DIR"] = if is_xcode_sdk
MacOS::Xcode.prefix
MacOS::Xcode.prefix.to_s
else
MacOS::CLT::PKG_PATH
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_assertions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Homebrew
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/formula_assertions.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# typed: strict

module Homebrew::Assertions
include Kernel
end
10 changes: 5 additions & 5 deletions Library/Homebrew/keg_relocate.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

class Keg
Expand Down Expand Up @@ -44,7 +44,7 @@ def replace_text(text)
key.is_a?(String) ? key.length : 999
end.reverse

any_changed = false
any_changed = T.let(nil, T.nilable(String))
sorted_keys.each do |key|
changed = text.gsub!(key, replacements[key])
any_changed ||= changed
Expand Down Expand Up @@ -144,7 +144,7 @@ def openjdk_dep_name_if_applicable
def replace_text_in_files(relocation, files: nil)
files ||= text_files | libtool_files

changed_files = []
changed_files = T.let([], Array)
files.map(&path.method(:join)).group_by { |f| f.stat.ino }.each_value do |first, *rest|
s = first.open("rb", &:read)

Expand Down Expand Up @@ -179,11 +179,11 @@ def relocate_build_prefix(keg, old_prefix, new_prefix)
binary = File.binread file
odebug "Replacing build prefix in: #{file}"
binary_strings = binary.split(/#{NULL_BYTE}/o, -1)
match_indices = binary_strings.each_index.select { |i| binary_strings[i].include?(old_prefix) }
match_indices = binary_strings.each_index.select { |i| binary_strings.fetch(i).include?(old_prefix) }

# Only perform substitution on strings which match prefix regex.
match_indices.each do |i|
s = binary_strings[i]
s = binary_strings.fetch(i)
binary_strings[i] = s.gsub(old_prefix, new_prefix)
.ljust(s.size, NULL_BYTE)
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/language/python.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Language
Expand Down
11 changes: 11 additions & 0 deletions Library/Homebrew/language/python.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# typed: strict

module Language::Python
module Shebang
include Kernel
end

module Virtualenv
requires_ancestor { Formula }
end
end
8 changes: 3 additions & 5 deletions Library/Homebrew/test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

raise "#{__FILE__} must not be loaded via `require`." if $PROGRAM_NAME != __FILE__
Expand Down Expand Up @@ -38,12 +38,10 @@
formula.extend(Debrew::Formula) if args.debug?

ENV.extend(Stdenv)
T.cast(ENV, Stdenv).setup_build_environment(formula: formula, testing_formula: true)
ENV.setup_build_environment(formula: formula, testing_formula: true)

# tests can also return false to indicate failure
run_test = proc do
raise "test returned false" if formula.run_test(keep_tmp: args.keep_tmp?) == false
end
run_test = proc { |_ = nil| raise "test returned false" if formula.run_test(keep_tmp: args.keep_tmp?) == false }
if args.debug? # --debug is interactive
run_test.call
else
Expand Down
8 changes: 3 additions & 5 deletions Library/Homebrew/unlink.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Homebrew
# Provides helper methods for unlinking formulae and kegs with consistent output.
module Unlink
module_function

def unlink_versioned_formulae(formula, verbose: false)
def self.unlink_versioned_formulae(formula, verbose: false)
formula.versioned_formulae
.select(&:keg_only?)
.select(&:linked?)
Expand All @@ -18,7 +16,7 @@ def unlink_versioned_formulae(formula, verbose: false)
end
end

def unlink(keg, dry_run: false, verbose: false)
def self.unlink(keg, dry_run: false, verbose: false)
options = { dry_run: dry_run, verbose: verbose }

keg.lock do
Expand Down
11 changes: 5 additions & 6 deletions Library/Homebrew/utils/analytics.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "context"
Expand Down Expand Up @@ -42,7 +42,6 @@ def report_google(type, metadata = {})
--data av=#{HOMEBREW_VERSION}
]
metadata.each do |key, value|
next unless key
next unless value

key = ERB::Util.url_encode key
Expand Down Expand Up @@ -146,13 +145,13 @@ def report_influx_event(measurement, package_and_options, on_request: false)
report_influx(measurement, package_and_options, on_request, additional_tags_influx)
end

sig { params(exception: Exception).void }
sig { params(exception: BuildError).void }
def report_build_error(exception)
report_google_build_error(exception)
report_influx_error(exception)
end

sig { params(exception: Exception).void }
sig { params(exception: BuildError).void }
def report_google_build_error(exception)
return if not_this_run? || disabled?

Expand All @@ -165,10 +164,10 @@ def report_google_build_error(exception)
else
formula_full_name
end
report_google_event("BuildError", package_and_options)
report_google_event(:BuildError, package_and_options)
end

sig { params(exception: Exception).void }
sig { params(exception: BuildError).void }
def report_influx_error(exception)
return if not_this_run? || disabled?

Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/utils/autoremove.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Utils
Expand All @@ -25,15 +25,15 @@ def formulae_with_cask_dependents(casks)
def formulae_with_no_formula_dependents(formulae)
return [] if formulae.blank?

dependents = []
dependents = T.let([], T::Array[Formula])
formulae.each do |formula|
dependents += formula.runtime_formula_dependencies

# Ignore build dependencies when the formula is a bottle
next if Tab.for_keg(formula.any_installed_keg).poured_from_bottle

formula.deps.select(&:build?).each do |dep|
suppress(FormulaUnavailableError) { dependents << dep.to_formula }
Kernel.suppress(FormulaUnavailableError) { dependents << dep.to_formula }
end
end
formulae - dependents
Expand Down
14 changes: 7 additions & 7 deletions Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "open3"
Expand Down Expand Up @@ -243,8 +243,8 @@ def curl_check_http_content(url, url_type, specs: {}, user_agents: [:default],
return unless url.start_with? "http"

secure_url = url.sub(/\Ahttp:/, "https:")
secure_details = nil
hash_needed = false
secure_details = T.let(nil, T.nilable(T::Hash[Symbol, T.untyped]))
hash_needed = T.let(false, T::Boolean)
if url != secure_url
user_agents.each do |user_agent|
secure_details = begin
Expand All @@ -267,7 +267,7 @@ def curl_check_http_content(url, url_type, specs: {}, user_agents: [:default],
end
end

details = nil
details = T.let(nil, T.nilable(T::Hash[Symbol, T.untyped]))
user_agents.each do |user_agent|
details =
curl_http_content_headers_and_checksum(
Expand Down Expand Up @@ -414,7 +414,7 @@ def curl_http_content_headers_and_checksum(
# Unknown charset in Content-Type header
end
end
file_contents = File.read(file.path, **open_args)
file_contents = File.read(T.must(file.path), **open_args)
file_hash = Digest::SHA2.hexdigest(file_contents) if hash_needed
end

Expand All @@ -430,7 +430,7 @@ def curl_http_content_headers_and_checksum(
responses: responses,
}
ensure
file.unlink
T.must(file).unlink
end

def curl_supports_tls13?
Expand Down Expand Up @@ -547,7 +547,7 @@ def parse_curl_response(response_text)
return response unless response_text.match?(HTTP_STATUS_LINE_REGEX)

# Parse the status line and remove it
match = response_text.match(HTTP_STATUS_LINE_REGEX)
match = T.must(response_text.match(HTTP_STATUS_LINE_REGEX))
response[:status_code] = match["code"] if match["code"].present?
response[:status_text] = match["text"] if match["text"].present?
response_text = response_text.sub(%r{^HTTP/.* (\d+).*$\s*}, "")
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/utils/curl.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# typed: strict

module Utils::Curl
include Kernel
requires_ancestor { SystemCommand::Mixin }
end
Loading