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

replace interface{} with any #1560

Merged
merged 1 commit into from
Mar 16, 2024
Merged

replace interface{} with any #1560

merged 1 commit into from
Mar 16, 2024

Conversation

methane
Copy link
Member

@methane methane commented Mar 16, 2024

Description

Go 1.18 introduced any. Let's use it.

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

Summary by CodeRabbit

  • Refactor
    • Enhanced type specificity and code clarity by updating function and method signatures across various components to use the any type instead of interface{}.

Copy link

coderabbitai bot commented Mar 16, 2024

Walkthrough

The overall change focuses on updating the type system within the codebase, specifically transitioning from using interface{} to any for variadic arguments and variable declarations. This shift aims to enhance type specificity and code clarity, affecting method signatures and type declarations across various files. By adopting the any type, the changes promise improved type handling and safety, reflecting a modern approach to dealing with dynamic types in Go.

Changes

Files Change Summary
README.md, driver_test.go Update function signatures to use any type for variadic arguments and variable declarations.
errors.go Change Logger interface's Print method signature to accept a variadic of any.
fields.go Update type reference from interface{} to any in scanTypeUnknown declaration.
nulltime.go, nulltime_test.go Modify method signatures to accept any type.
statement.go, statement_test.go Update parameter types to use any instead of interface{}.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@methane methane requested a review from shogo82148 March 16, 2024 03:40
@methane
Copy link
Member Author

methane commented Mar 16, 2024

Although this is not a bugfix, I will backport this into 1.8.
It makes easy to backport bugfixes.

@methane methane changed the title replace interface{} with any replace interface{} with any Mar 16, 2024
@coveralls
Copy link

Coverage Status

coverage: 81.989%. remained the same
when pulling 3a50386 on methane:any
into 8a327a3 on go-sql-driver:master.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8a327a3 and 3a50386.
Files selected for processing (8)
  • README.md (1 hunks)
  • driver_test.go (12 hunks)
  • errors.go (1 hunks)
  • fields.go (1 hunks)
  • nulltime.go (1 hunks)
  • nulltime_test.go (1 hunks)
  • statement.go (1 hunks)
  • statement_test.go (2 hunks)
Additional comments: 9
nulltime_test.go (1)
  • 26-26: The change from interface{} to any aligns with the PR's goal of adopting Go 1.18's any type for improved code clarity. It's a good practice to add a brief comment explaining the use of any over interface{} for those who might not be familiar with this update in Go 1.18.
nulltime.go (1)
  • 41-41: The update to use any in the Scan method's parameter type is a good improvement for code readability, aligning with the PR's objectives. Consider adding a comment about the use of any for those unfamiliar with this Go 1.18 update.
errors.go (2)
  • 44-44: The update to use any in the Logger interface's Print method signature enhances code readability and aligns with the PR's objectives. Consider adding a comment about the use of any for those unfamiliar with this Go 1.18 update.
  • 51-51: Similarly, the update in the NopLogger struct's Print method signature to use any is a good improvement for code readability. Adding a brief comment about the use of any could be helpful for clarity.
statement_test.go (2)
  • 80-80: The update to use any in the TestConvertSignedIntegers function enhances code readability and aligns with the PR's objectives. Consider adding a comment about the use of any for those unfamiliar with this Go 1.18 update.
  • 109-109: Similarly, the update in the TestConvertUnsignedIntegers function to use any is a good improvement for code readability. Adding a brief comment about the use of any could be helpful for clarity.
fields.go (1)
  • 137-137: The update in the scanTypeUnknown declaration to use any enhances code readability and aligns with the PR's objectives. Consider adding a comment about the use of any for those unfamiliar with this Go 1.18 update.
statement.go (1)
  • 144-144: The update to use any in the ConvertValue method's parameter type is a good improvement for code readability, aligning with the PR's objectives. Consider adding a comment about the use of any for those unfamiliar with this Go 1.18 update.
README.md (1)
  • 329-329: The change from interface{} to any in the function signature within the README.md is consistent with the PR's objectives to leverage Go 1.18's any type for better readability. This update should make the example code clearer to readers.

Comment on lines 247 to 253
dbt.Fatalf("error on %s %s: %s", method, query, err.Error())
}

func (dbt *DBTest) mustExec(query string, args ...interface{}) (res sql.Result) {
func (dbt *DBTest) mustExec(query string, args ...any) (res sql.Result) {
dbt.Helper()
res, err := dbt.db.Exec(query, args...)
if err != nil {
Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1494-1496]

The TLS configuration is missing the MinVersion field. It's a good practice to explicitly set the minimum version of TLS to TLS 1.3 to ensure the use of secure protocols. Consider adding MinVersion: tls.VersionTLS13 to the TLS configuration.

tls.Config{
  InsecureSkipVerify: true,
+ MinVersion: tls.VersionTLS13,
}

Comment on lines 326 to 332

```go
conn, _ := db.Conn(ctx)
conn.Raw(func(conn interface{}) error {
conn.Raw(func(conn any) error {
ex := conn.(driver.Execer)
res, err := ex.Exec(`
UPDATE point SET x = 1 WHERE y = 2;
Copy link

@coderabbitai coderabbitai bot Mar 16, 2024

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [3-3]

There's a possible spelling mistake with "MySQL-Driver". Consider specifying it as "MySQL driver" for clarity and consistency with common terminology.

- A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) package
+ A MySQL driver for Go's [database/sql](https://golang.org/pkg/database/sql/) package

Copy link
Contributor

Choose a reason for hiding this comment

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

@coderabbitai If this is "outside the diff hunks", why are you posting this here? This is just irrelevant.

Copy link

Choose a reason for hiding this comment

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

@dolmen, thank you for your feedback. You're correct that the comment was outside the modified lines in the pull request, and I understand your concern about the relevance of such comments to the immediate changes.

The automated review process is designed to ensure overall quality and consistency throughout the file, which sometimes includes suggestions on parts of the file not directly modified but still visible in the broader context of the pull request. However, I appreciate that the primary focus should be on the changes made in the diff hunks.

If you prefer, I can adjust the settings to limit comments to only the lines modified in the pull request. Would you like me to make this change for future reviews?

Copy link
Member Author

Choose a reason for hiding this comment

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

@dolmen See https://github.com/apps/coderabbitai
I just trying it. It is far from perfect, but interesting enough.

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@methane methane mentioned this pull request Mar 16, 2024
5 tasks
Copy link
Contributor

@shogo82148 shogo82148 left a comment

Choose a reason for hiding this comment

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

LGTM

@methane methane merged commit 35847be into go-sql-driver:master Mar 16, 2024
32 checks passed
@methane methane deleted the any branch March 16, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants