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

Added sorbet typecheck under python module on 5 files #11261

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

randhircs
Copy link
Member

@randhircs randhircs commented Jan 9, 2025

What are you trying to accomplish?

Requirement is to add Sorbet TypeCheck under Python module, Selected files are updated with TypeCheck.

Anything you want to highlight for special attention from reviewers?

TypeCheck are having correct data type params and return data type.

How will you know you've accomplished your goal?

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@randhircs randhircs requested a review from a team as a code owner January 9, 2025 20:47
@randhircs randhircs marked this pull request as draft January 9, 2025 20:47
@randhircs randhircs changed the title Added sorbet typecheck under python module Added sorbet typecheck under python module on 5 files Jan 9, 2025
@randhircs randhircs self-assigned this Jan 10, 2025
@randhircs randhircs marked this pull request as ready for review January 10, 2025 02:41
@randhircs randhircs force-pushed the randhircs/dependabot-core-sorbet-python01 branch from 0032c61 to 601f7de Compare January 10, 2025 13:47
markhallen
markhallen previously approved these changes Jan 10, 2025
Copy link
Member

@abdulapopoola abdulapopoola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to change the typed:true to typed:strict; see this example

@randhircs
Copy link
Member Author

Sure, I change it.

@randhircs randhircs force-pushed the randhircs/dependabot-core-sorbet-python01 branch from 1b814d7 to 6799716 Compare January 13, 2025 22:34
@randhircs randhircs closed this Jan 13, 2025
@randhircs randhircs reopened this Jan 13, 2025
@randhircs randhircs closed this Jan 13, 2025
@randhircs randhircs reopened this Jan 13, 2025
@randhircs randhircs force-pushed the randhircs/dependabot-core-sorbet-python01 branch from 6799716 to bf7b0ec Compare January 14, 2025 14:48
@randhircs randhircs force-pushed the randhircs/dependabot-core-sorbet-python01 branch from aca58f5 to 955f98a Compare January 14, 2025 19:30
@@ -198,14 +198,15 @@ def setup_python_environment
nil
end

sig { params(package_manager: String, version: String).void }
sig { params(package_manager: String, version: String).returns(T.nilable(T::Boolean)) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a nilable boolean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I also think all conditions are handled. It shouldn't be nillable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I corrected it now, thanks to both of you.

@@ -383,6 +394,7 @@ def parsed_requirement_files
raise Dependabot::DependencyFileNotEvaluatable, e.message
end

sig { params(requirements: T.untyped).returns(T.untyped) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are requirements actually untyped?

@@ -8,11 +8,13 @@
require "dependabot/python/file_parser"
require "dependabot/python/native_helpers"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update the typed: strict here too?

@@ -32,7 +33,7 @@ class FileParser < Dependabot::FileParsers::Base
pipfile: "dev-packages",
lockfile: "develop"
}
].freeze
].freeze, T::Array[T::Hash[T.untyped, T.untyped]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested Change: Instead of using T::Hash[T.untyped, T.untyped], use T::Hash[Symbol, String] (or another more specific type) to improve type safety and clarity.

Reasoning:

  • T.untyped allows any type, which weakens Sorbet’s ability to provide meaningful type checks.
  • By specifying Symbol as the key type and String as the value type (or another suitable type if necessary), you:
    • Make the code's intent clearer.
    • Enable Sorbet to catch potential mismatches early.
    • Provide better documentation for others reading or maintaining the code.

def group_from_filename(filename)
if filename.include?("dev") then ["dev-dependencies"]
else
["dependencies"]
end
end

sig { params(dep: T.untyped).returns(T::Boolean) }
def blocking_marker?(dep)
Copy link
Contributor

@kbukum1 kbukum1 Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this T.untyped? Is it something changing dependency to the situation?

@@ -316,6 +320,9 @@ def blocking_marker?(dep)
end
end

sig do
params(marker: T.untyped, python_version: T.any(String, Integer, Gem::Version)).returns(T::Boolean)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think T.untyped is not proper unless necessary

@@ -337,6 +344,10 @@ def marker_satisfied?(marker, python_version)
result
end

sig do
params(condition: T.untyped,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, T.untyped?

end

sig { returns(T.untyped) }
Copy link
Contributor

@kbukum1 kbukum1 Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do have return type here but not sure.

Copy link
Contributor

@kbukum1 kbukum1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think mostly there are lots of T.untyped which is not preferred approach. The typing doesn't have any value when it is T.untyped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants