Skip to content

Commit a0bc83d

Browse files
committed
fix(types): resolve Steep type checking errors
- Make train_batch params nilable (?(Type)? syntax) in all classifiers - Add _StreamingHost interface for Streaming module dependencies - Fix TFIDF stub methods with proper RBS and steep:ignore - Make Matrix/Vector non-generic in vendor RBS - Add Enumerable type param to LineReader
1 parent 163b8c9 commit a0bc83d

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

lib/classifier/bayes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def train_from_stream(category, io, batch_size: Streaming::DEFAULT_BATCH_SIZE)
354354
# puts "#{progress.percent}% complete"
355355
# end
356356
#
357-
# @rbs (?(String | Symbol), ?Array[String], ?batch_size: Integer, **Array[String]) { (Streaming::Progress) -> void } -> void
357+
# @rbs (?(String | Symbol)?, ?Array[String]?, ?batch_size: Integer, **Array[String]) { (Streaming::Progress) -> void } -> void
358358
def train_batch(category = nil, documents = nil, batch_size: Streaming::DEFAULT_BATCH_SIZE, **categories, &block)
359359
if category && documents
360360
train_batch_for_category(category, documents, batch_size: batch_size, &block)

lib/classifier/logistic_regression.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def train_from_stream(category, io, batch_size: Streaming::DEFAULT_BATCH_SIZE)
399399
# classifier.train_batch(spam: documents, ham: other_docs)
400400
# classifier.fit
401401
#
402-
# @rbs (?(String | Symbol), ?Array[String], ?batch_size: Integer, **Array[String]) { (Streaming::Progress) -> void } -> void
402+
# @rbs (?(String | Symbol)?, ?Array[String]?, ?batch_size: Integer, **Array[String]) { (Streaming::Progress) -> void } -> void
403403
def train_batch(category = nil, documents = nil, batch_size: Streaming::DEFAULT_BATCH_SIZE, **categories, &block)
404404
if category && documents
405405
train_batch_for_category(category, documents, batch_size: batch_size, &block)

lib/classifier/lsi.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def add_batch(batch_size: Streaming::DEFAULT_BATCH_SIZE, **items)
709709
# Alias train_batch to add_batch for API consistency with other classifiers.
710710
# Note: LSI uses categories differently (items have categories, not the training call).
711711
#
712-
# @rbs (?(String | Symbol), ?Array[String], ?batch_size: Integer, **Array[String]) { (Streaming::Progress) -> void } -> void
712+
# @rbs (?(String | Symbol)?, ?Array[String]?, ?batch_size: Integer, **Array[String]) { (Streaming::Progress) -> void } -> void
713713
def train_batch(category = nil, documents = nil, batch_size: Streaming::DEFAULT_BATCH_SIZE, **categories, &block)
714714
if category && documents
715715
add_batch(batch_size: batch_size, **{ category.to_sym => documents }, &block)

lib/classifier/streaming.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def train_from_stream(category, io, batch_size: DEFAULT_BATCH_SIZE, &block)
4040
# @example Keyword style
4141
# classifier.train_batch(spam: documents, ham: other_docs, batch_size: 100)
4242
#
43-
# @rbs (?(Symbol | String), ?Array[String], ?batch_size: Integer, **Array[String]) { (Progress) -> void } -> void
43+
# @rbs (?(Symbol | String)?, ?Array[String]?, ?batch_size: Integer, **Array[String]) { (Progress) -> void } -> void
4444
def train_batch(category = nil, documents = nil, batch_size: DEFAULT_BATCH_SIZE, **categories, &block)
4545
raise NotImplementedError, "#{self.class} must implement train_batch"
4646
end

lib/classifier/tfidf.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,16 @@ def fit_from_stream(io, batch_size: Streaming::DEFAULT_BATCH_SIZE)
299299
# TFIDF doesn't support train_from_stream (use fit_from_stream instead).
300300
# This method raises NotImplementedError with guidance.
301301
#
302-
# @rbs (untyped, untyped, **untyped) -> void
303-
def train_from_stream(*)
302+
# @rbs (*untyped, **untyped) -> void
303+
def train_from_stream(*) # steep:ignore
304304
raise NotImplementedError, 'TFIDF uses fit_from_stream instead of train_from_stream'
305305
end
306306

307307
# TFIDF doesn't support train_batch (use fit instead).
308308
# This method raises NotImplementedError with guidance.
309309
#
310-
# @rbs (**untyped) -> void
311-
def train_batch(*)
310+
# @rbs (*untyped, **untyped) -> void
311+
def train_batch(*) # steep:ignore
312312
raise NotImplementedError, 'TFIDF uses fit instead of train_batch'
313313
end
314314

sig/vendor/streaming.rbs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Type stubs for Streaming module
2+
# Defines the interface that including classes must implement
3+
4+
module Classifier
5+
# Interface for classes that include Streaming
6+
interface _StreamingHost
7+
def storage: () -> Storage::Base?
8+
def storage=: (Storage::Base?) -> void
9+
def save: () -> void
10+
end
11+
12+
module Streaming : _StreamingHost
13+
end
14+
end

0 commit comments

Comments
 (0)