Superscript question marks being added to return types

125 views
Skip to first unread message

Perry Smith

unread,
May 18, 2020, 11:44:16 AM5/18/20
to YARD
If I put a type list such as @return [Integer, nil], the output has Integer with a question mark superscript (I don't know how to get this editor to do that).  If I change it to be two @return tags, that works for public methods but not for private methods.

Perry Smith

unread,
May 18, 2020, 12:03:47 PM5/18/20
to YARD

#safe_pos ⇒ Integer?  (private)


example.  I'm using the latest Yard 0.9.25 and Ruby 2.7.0

Loren Segal

unread,
May 18, 2020, 3:08:00 PM5/18/20
to yar...@googlegroups.com

I'm a little unclear on what you mean by "that works", because I'm not sure what behavior you're expecting. Also, can you provide a code sample that is producing your result? Based on what I am seeing, both public and private methods behave the same way for the same docstring on my end:

class A
  # @return [Integer] x
  # @return [nil] y
  def foo
  end
  private
  # @return [Integer] x
  # @return [nil] y
  def bar
  end
end

(Correctly) produces:

Loren

--

---
You received this message because you are subscribed to the Google Groups "YARD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yardoc+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/yardoc/43a97cb3-3094-487c-8651-622af44a5823%40googlegroups.com.

Perry Smith

unread,
May 18, 2020, 3:32:51 PM5/18/20
to YARD

#gets ⇒ nilLine

is what I would prefer.

  # @return [nil] if EOF
  # @return [Line] the next line in the file
  def gets
    return get_line
  end

  private

  # @return [Integer]
  # @return [nil] if
  #   raises an exception
  def safe_pos
    return @file.pos
  rescue Errno::ESPIPE, ArgumentError
    return nil
  end


On Monday, May 18, 2020 at 10:44:16 AM UTC-5, Perry Smith wrote:

Perry Smith

unread,
May 18, 2020, 3:36:01 PM5/18/20
to YARD
It may be that the ? is what you want.  And, I'm not objecting to it.  I just never noticed it and didn't know what it meant or if it was intended.

Perry Smith

unread,
May 18, 2020, 3:39:45 PM5/18/20
to YARD
FYI: I get the same #gets => nil, Line in the method summary at the top of the page and in #gets detailed description.

Perry Smith

unread,
May 18, 2020, 3:46:15 PM5/18/20
to YARD
This:

  # @return [nil] if
  #   raises an exception
  # @return [Integer]
  def safe_pos
    return @file.pos
  rescue Errno::ESPIPE, ArgumentError
    return nil
  end

produces

#safe_pos ⇒ nilInteger  (private)


while this (reversing the order of the return tags):

  # @return [Integer]
  # @return [nil] if
  #   raises an exception
  def safe_pos
    return @file.pos
  rescue Errno::ESPIPE, ArgumentError
    return nil
  end

#safe_pos ⇒ Integer?  (private)




Perry Smith

unread,
May 18, 2020, 4:01:14 PM5/18/20
to YARD
The same thing happens if the return tag has both types listed in a single line.  e.g.

  # @return [Line, nil] the next line from file(s) or +nil+ at +EOF+

produces 

#get_line ⇒ Line?  (private)


while

  # @return [nil, Line] the next line from file(s) or +nil+ at +EOF+

produces

#get_line ⇒ nilLine  (private)


Sorry if I'm overloading you with data :-). Looks like now I have a work around and can decide which output I prefer

Loren Segal

unread,
May 18, 2020, 4:26:22 PM5/18/20
to yar...@googlegroups.com

The behavior is indeed intentional. The question mark indicates that the field is nullable [Integer, nil] is the right way to specify a nullable type. Using [nil, Integer] will break YARD because it doesn't understand which field is nullable -- arguably it could figure it out but this enables the formatting workaround you described so there is no need to change the behavior.

Loren

--

---
You received this message because you are subscribed to the Google Groups "YARD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yardoc+un...@googlegroups.com.

André Barros

unread,
Oct 30, 2023, 5:31:17 PM10/30/23
to YARD
RENDER

André Barros

unread,
Oct 30, 2023, 5:34:06 PM10/30/23
to YARD
I HAVE
Reply all
Reply to author
Forward
0 new messages