Skip to content

Commit f6dfe6f

Browse files
chore: fix misc rubocop errors (#74)
1 parent 918389e commit f6dfe6f

File tree

12 files changed

+44
-31
lines changed

12 files changed

+44
-31
lines changed

.rubocop.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ Metrics/ParameterLists:
118118
Metrics/PerceivedComplexity:
119119
Enabled: false
120120

121+
# Need to preserve block identifier for documentation.
121122
Naming/BlockForwarding:
122-
Exclude:
123-
- "**/*.rbi"
123+
Enabled: false
124124

125125
Naming/ClassAndModuleCamelCase:
126126
Exclude:
@@ -153,6 +153,9 @@ Style/Alias:
153153
Style/AndOr:
154154
EnforcedStyle: always
155155

156+
Style/ArgumentsForwarding:
157+
Enabled: false
158+
156159
Style/BisectedAttrAccessor:
157160
Exclude:
158161
- "**/*.rbi"

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ xargs = %w[xargs --no-run-if-empty --null --max-procs=0 --max-args=300 --]
1414
multitask(default: [:test])
1515

1616
multitask(:test) do
17-
rb =
17+
rb =
1818
FileList[ENV.fetch("TEST", "./test/**/*_test.rb")]
1919
.map { "require_relative(#{_1.dump});" }
2020
.join

Steepfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ target :lib do
99

1010
YAML.safe_load_file("./manifest.yaml", symbolize_names: true) => { dependencies: }
1111
# currently these libraries lack the `*.rbs` annotations required by `steep`
12-
stdlibs = dependencies - %w[etc net/http rbconfig set stringio]
12+
stdlibs = dependencies - %w[English etc net/http rbconfig set stringio]
1313

1414
stdlibs.each { library(_1) }
1515
end

lib/openai.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
# frozen_string_literal: true
22

3-
# We already ship the preferred sorbet manifests in the package itself.
4-
# `tapioca` currently does not offer us a way to opt out of unnecessary compilation.
5-
if Object.const_defined?(:Tapioca) && caller.chain([$0]).chain(ARGV).grep(/tapioca/)
6-
Warning.warn(
7-
<<~WARN
8-
\n
9-
⚠️ skipped loading of "openai" gem under `tapioca`.
10-
11-
This message is normal and expected if you are running a `tapioca` command, and does not impact `.rbi` generation.
12-
\n
13-
WARN
14-
)
15-
return
16-
end
17-
183
# Standard libraries.
4+
require "English"
195
require "cgi"
206
require "date"
217
require "erb"
@@ -30,6 +16,21 @@
3016
require "time"
3117
require "uri"
3218

19+
# We already ship the preferred sorbet manifests in the package itself.
20+
# `tapioca` currently does not offer us a way to opt out of unnecessary compilation.
21+
if Object.const_defined?(:Tapioca) && caller.chain([$PROGRAM_NAME]).chain(ARGV).grep(/tapioca/)
22+
Warning.warn(
23+
<<~WARN
24+
\n
25+
⚠️ skipped loading of "openai" gem under `tapioca`.
26+
27+
This message is normal and expected if you are running a `tapioca` command, and does not impact `.rbi` generation.
28+
\n
29+
WARN
30+
)
31+
return
32+
end
33+
3334
# Gems.
3435
require "connection_pool"
3536

lib/openai/transport/pooled_net_requester.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def calibrate_socket_timeout(conn, deadline)
5454
#
5555
# @yieldparam [String]
5656
# @return [Net::HTTPGenericRequest]
57-
def build_request(request, &)
57+
def build_request(request, &blk)
5858
method, url, headers, body = request.fetch_values(:method, :url, :headers, :body)
5959
req = Net::HTTPGenericRequest.new(
6060
method.to_s.upcase,
@@ -70,13 +70,13 @@ def build_request(request, &)
7070
nil
7171
in String
7272
req["content-length"] ||= body.bytesize.to_s unless req["transfer-encoding"]
73-
req.body_stream = OpenAI::Util::ReadIOAdapter.new(body, &)
73+
req.body_stream = OpenAI::Util::ReadIOAdapter.new(body, &blk)
7474
in StringIO
7575
req["content-length"] ||= body.size.to_s unless req["transfer-encoding"]
76-
req.body_stream = OpenAI::Util::ReadIOAdapter.new(body, &)
76+
req.body_stream = OpenAI::Util::ReadIOAdapter.new(body, &blk)
7777
in IO | Enumerator
7878
req["transfer-encoding"] ||= "chunked" unless req["content-length"]
79-
req.body_stream = OpenAI::Util::ReadIOAdapter.new(body, &)
79+
req.body_stream = OpenAI::Util::ReadIOAdapter.new(body, &blk)
8080
end
8181

8282
req

lib/openai/type/array_of.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def ===(other) = other.is_a?(Array) && other.all?(item_type)
3131
# @param other [Object]
3232
#
3333
# @return [Boolean]
34-
def ==(other) = other.is_a?(OpenAI::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type
34+
def ==(other)
35+
other.is_a?(OpenAI::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type
36+
end
3537

3638
# @api private
3739
#

lib/openai/type/base_model.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def fields
9494
end
9595
rescue StandardError
9696
cls = self.class.name.split("::").last
97+
# rubocop:disable Layout/LineLength
9798
message = "Failed to parse #{cls}.#{__method__} from #{value.class} to #{target.inspect}. To get the unparsed API response, use #{cls}[:#{__method__}]."
99+
# rubocop:enable Layout/LineLength
98100
raise OpenAI::ConversionError.new(message)
99101
end
100102
end
@@ -205,14 +207,13 @@ def coerce(value, state:)
205207
instance = new
206208
data = instance.to_h
207209

210+
# rubocop:disable Metrics/BlockLength
208211
fields.each do |name, field|
209212
mode, required, target = field.fetch_values(:mode, :required, :type)
210213
api_name, nilable, const = field.fetch_values(:api_name, :nilable, :const)
211214

212215
unless val.key?(api_name)
213-
if const != OpenAI::Util::OMIT
214-
exactness[:yes] += 1
215-
elsif required && mode != :dump
216+
if required && mode != :dump && const == OpenAI::Util::OMIT
216217
exactness[nilable ? :maybe : :no] += 1
217218
else
218219
exactness[:yes] += 1
@@ -238,6 +239,7 @@ def coerce(value, state:)
238239
end
239240
data.store(name, converted)
240241
end
242+
# rubocop:enable Metrics/BlockLength
241243

242244
keys.each { data.store(_1, val.fetch(_1)) }
243245
instance

lib/openai/type/base_page.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def next_page = (raise NotImplementedError)
3636
# @param blk [Proc]
3737
#
3838
# @return [void]
39-
def auto_paging_each(&) = (raise NotImplementedError)
39+
def auto_paging_each(&blk) = (raise NotImplementedError)
4040

4141
# @return [Enumerable]
4242
def to_enum = super(:auto_paging_each)

lib/openai/type/base_stream.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def close = OpenAI::Util.close_fused!(@iterator)
3131
# @param blk [Proc]
3232
#
3333
# @return [void]
34-
def each(&)
34+
def each(&blk)
3535
unless block_given?
3636
raise ArgumentError.new("A block must be given to ##{__method__}")
3737
end
38-
@iterator.each(&)
38+
@iterator.each(&blk)
3939
end
4040

4141
# @return [Enumerator]

lib/openai/type/hash_of.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def ===(other)
4646
# @param other [Object]
4747
#
4848
# @return [Boolean]
49-
def ==(other) = other.is_a?(OpenAI::HashOf) && other.nilable? == nilable? && other.item_type == item_type
49+
def ==(other)
50+
other.is_a?(OpenAI::HashOf) && other.nilable? == nilable? && other.item_type == item_type
51+
end
5052

5153
# @api private
5254
#

0 commit comments

Comments
 (0)