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

Fixed sorbet types as strict for Python Module #11432

Merged
merged 2 commits into from
Jan 29, 2025
Merged
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
22 changes: 18 additions & 4 deletions python/lib/dependabot/python/file_updater/pipfile_preparer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "toml-rb"
Expand All @@ -12,10 +12,14 @@ module Dependabot
module Python
class FileUpdater
class PipfilePreparer
extend T::Sig

sig { params(pipfile_content: String).void }
def initialize(pipfile_content:)
@pipfile_content = pipfile_content
end

sig { params(credentials: T::Array[T::Hash[String, T.untyped]]).returns(String) }
def replace_sources(credentials)
pipfile_object = TomlRB.parse(pipfile_content)

Expand All @@ -26,6 +30,7 @@ def replace_sources(credentials)
TomlRB.dump(pipfile_object)
end

sig { params(requirement: String).returns(String) }
def update_python_requirement(requirement)
pipfile_object = TomlRB.parse(pipfile_content)

Expand All @@ -39,6 +44,7 @@ def update_python_requirement(requirement)
TomlRB.dump(pipfile_object)
end

sig { params(parsed_file: String).returns(String) }
def update_ssl_requirement(parsed_file)
pipfile_object = TomlRB.parse(pipfile_content)
parsed_object = TomlRB.parse(parsed_file)
Expand All @@ -56,13 +62,19 @@ def update_ssl_requirement(parsed_file)

private

sig { returns(String) }
attr_reader :pipfile_content
attr_reader :lockfile

sig { returns(T::Array[T::Hash[String, T.untyped]]) }
def pipfile_sources
@pipfile_sources ||= TomlRB.parse(pipfile_content).fetch("source", [])
@pipfile_sources ||= T.let(TomlRB.parse(pipfile_content).fetch("source", []),
T.nilable(T::Array[T::Hash[String, T.untyped]]))
end

sig do
params(source: T::Hash[String, T.untyped],
credentials: T::Array[T::Hash[String, T.untyped]]).returns(T.nilable(T::Hash[String, T.untyped]))
end
def sub_auth_url(source, credentials)
if source["url"].include?("${")
base_url = source["url"].sub(/\${.*}@/, "")
Expand All @@ -79,8 +91,10 @@ def sub_auth_url(source, credentials)
source
end

sig { params(credentials: T::Array[T::Hash[String, T.untyped]]).returns(T::Array[T::Hash[String, T.untyped]]) }
def config_variable_sources(credentials)
@config_variable_sources ||=
@config_variable_sources = T.let([], T.nilable(T::Array[T::Hash[String, T.untyped]]))
@config_variable_sources =
credentials.select { |cred| cred["type"] == "python_index" }.map.with_index do |c, i|
{
"name" => "dependabot-inserted-index-#{i}",
Expand Down
Loading