Skip to content

Commit 58194c0

Browse files
committed
chore: run modernize
1 parent f8b8a30 commit 58194c0

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

api_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func (ac *apiClient) uploadFile(ctx context.Context, r io.Reader, uploadURL stri
575575
} else if err != nil {
576576
return nil, fmt.Errorf("Failed to read bytes from file at offset %d: %w. Bytes actually read: %d", offset, err, bytesRead)
577577
}
578-
for attempt := 0; attempt < maxRetryCount; attempt++ {
578+
for attempt := range maxRetryCount {
579579
patchedHTTPOptions, err := patchHTTPOptions(ac.clientConfig.HTTPOptions, *httpOptions)
580580
if err != nil {
581581
return nil, err

api_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ func createTestFile(t *testing.T, size int64) (string, func()) {
13101310

13111311
buf := make([]byte, 1024*1024) // 1MB buffer
13121312
pattern := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()")
1313-
for i := 0; i < len(buf); i++ {
1313+
for i := range buf {
13141314
buf[i] = pattern[i%len(pattern)]
13151315
}
13161316

common.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"iter"
2323
"log"
24+
"maps"
2425
"net/http"
2526
"net/url"
2627
"reflect"
@@ -135,9 +136,7 @@ func setValueByPath(data map[string]any, keys []string, value any) {
135136
if newMap, ok2 := value.(map[string]any); ok2 {
136137
// Instead of overwriting dictionary with another dictionary, merge them.
137138
// This is important for handling training and validation datasets in tuning.
138-
for k, v := range newMap {
139-
existingMap[k] = v
140-
}
139+
maps.Copy(existingMap, newMap)
141140
data[finalKey] = existingMap // Assign the updated map back
142141
}
143142
} else {
@@ -147,9 +146,7 @@ func setValueByPath(data map[string]any, keys []string, value any) {
147146
if finalKey == "_self" && reflect.TypeOf(value).Kind() == reflect.Map {
148147
// Iterate through the `value` map and copy its contents to `data`.
149148
if valMap, ok := value.(map[string]any); ok {
150-
for k, v := range valMap {
151-
data[k] = v
152-
}
149+
maps.Copy(data, valMap)
153150
}
154151
} else {
155152
// If existing_data is None (or key doesn't exist), set the value directly.

pages.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"errors"
2020
"iter"
21+
"maps"
2122
)
2223

2324
// ErrPageDone is the error returned by an iterator's Next method when no more pages are available.
@@ -88,9 +89,7 @@ func (p Page[T]) Next(ctx context.Context) (Page[T], error) {
8889
return p, ErrPageDone
8990
}
9091
c := make(map[string]any)
91-
for k, v := range p.config {
92-
c[k] = v
93-
}
92+
maps.Copy(c, p.config)
9493
c["PageToken"] = p.NextPageToken
9594

9695
return newPage[T](ctx, p.Name, c, p.listFunc)

replay_sanitizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func sanitizeMapWithSourceType(t *testing.T, sourceType reflect.Type, m any) {
6060
for _, path := range paths {
6161
if sourceType.Kind() == reflect.Slice {
6262
data := m.([]any)
63-
for i := 0; i < len(data); i++ {
63+
for i := range data {
6464
sanitizeMapByPath(data[i], path, stdBase64Handler, false)
6565
}
6666
} else {

transformer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ func tFileName(name any) (string, error) {
220220
return "", fmt.Errorf("could not extract file name from URI: %s", name)
221221
}
222222
name = match[0]
223-
} else if strings.HasPrefix(name, "files/") {
224-
name = strings.TrimPrefix(name, "files/")
223+
} else if after, ok := strings.CutPrefix(name, "files/"); ok {
224+
name = after
225225
}
226226
return name, nil
227227
}

0 commit comments

Comments
 (0)