Skip to content

Commit

Permalink
Added TypeCheck as strict for file_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
randhircs committed Jan 13, 2025
1 parent 55b5351 commit 6799716
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions python/lib/dependabot/python/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ def pipenv_dependencies
dependency_files).dependency_set, T.nilable(PipfileFilesParser))
end

sig { returns(T.nilable(PyprojectFilesParser))}
sig { returns(T.nilable(PyprojectFilesParser)) }
def pyproject_file_dependencies
@pyproject_file_dependencies ||= T.let(PyprojectFilesParser.new(dependency_files:
dependency_files).dependency_set, T.nilable(PyprojectFilesParser))
end

sig { returns(DependencySet)}
sig { returns(DependencySet) }
def requirement_dependencies
dependencies = DependencySet.new
parsed_requirement_files.each do |dep|
Expand Down Expand Up @@ -319,7 +319,9 @@ def blocking_marker?(dep)
end
end

sig { params(marker: T.untyped, python_version: T.nilable(T.any(String, Integer, Gem::Version))).returns(T::Boolean) }
sig do
params(marker: T.untyped, python_version: T.nilable(T.any(String, Integer, Gem::Version))).returns(T::Boolean)
end
def marker_satisfied?(marker, python_version)
conditions = marker.split(/\s+(and|or)\s+/)

Expand All @@ -341,6 +343,10 @@ def marker_satisfied?(marker, python_version)
result
end

sig do
params(condition: T.untyped,
python_version: T.nilable(T.any(String, Integer, Gem::Version))).returns(T::Boolean)
end
def evaluate_condition(condition, python_version)
operator, version = condition.match(/([<>=!]=?)\s*"?([\d.]+)"?/)&.captures

Expand All @@ -365,7 +371,8 @@ def setup_file_dependencies
@setup_file_dependencies ||= T.let(
SetupFileParser
.new(dependency_files: dependency_files)
.dependency_set, T.untyped)
.dependency_set, T.untyped
)
end

sig { returns(T.untyped) }
Expand Down Expand Up @@ -473,7 +480,7 @@ def poetry_lock
@poetry_lock ||= T.let(get_original_file("poetry.lock"), T.nilable(Dependabot::DependencyFile))
end

sig { returns(T.nilable(Dependabot::DependencyFile))}
sig { returns(T.nilable(Dependabot::DependencyFile)) }
def setup_file
@setup_file ||= T.let(get_original_file("setup.py"), T.nilable(Dependabot::DependencyFile))
end
Expand All @@ -483,7 +490,7 @@ def setup_cfg_file
@setup_cfg_file ||= T.let(get_original_file("setup.cfg"), T.nilable(Dependabot::DependencyFile))
end

sig { returns(T::Array[Dependabot::DependencyFile]) }
sig { returns(T::Array[Dependabot::Python::Requirement]) }
def pip_compile_files
@pip_compile_files ||= T.let(dependency_files.select { |f| f.name.end_with?(".in") }, T.untyped)
end
Expand Down

0 comments on commit 6799716

Please sign in to comment.