Skip to content

Commit

Permalink
Update signature handling in @overload
Browse files Browse the repository at this point in the history
Previously, `@overload` tags that defined required keyword arguments would end up with an empty default value, to the delight of nobody. While this might *ideally* be handled by moving away from the legacy parsers, this is a stopgap that makes an already uncommon edge case go away.
  • Loading branch information
pvande committed Oct 11, 2024
1 parent e96ae99 commit 7641cc5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/yard/tags/overload_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def parse_signature
args = YARD::Handlers::Ruby::Legacy::Base.new(nil, nil).send(:tokval_list, toks, :all)
args = args.map do |a|
k, v = *a.split(/:|=/, 2)
[k.strip.to_s + (a[k.size, 1] == ':' ? ':' : ''), (v ? v.strip : nil)]
v.strip! if v
[k.strip.to_s + (a[k.size, 1] == ':' ? ':' : ''), (v && v.empty? ? nil : v)]
end if args
@name = meth.to_sym
@parameters = args
Expand Down
15 changes: 15 additions & 0 deletions spec/tags/overload_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,19 @@ def bar(a, b = 1, &block)
tag = Tags::OverloadTag.new(:overload, "default")
expect(tag.signature).to eq "default"
end

it "properly handles complex signatures" do
tag = Tags::OverloadTag.new(:overload, "foo(a, b = 1, *c, d, e:, f: 2, g:, **rest, &block)")
expect(tag.parameters).to eq [
['a', nil],
['b', "1"],
['*c', nil],
['d', nil],
['e:', nil],
['f:', "2"],
['g:', nil],
['**rest', nil],
['&block', nil],
]
end
end

0 comments on commit 7641cc5

Please sign in to comment.