4

I have a question about how certain "help()" items show up in my Python 3.6.2 IDLE shell running on Windows. From the docs, I'd expect to see sum(iterable[, start]) and pow (x, y[, z]), but calling help on those yields sum(iterable, start=0, /) , and pow(x, y, z=None, /). There may be other functions that display the same way.

I'm curious about why they put the descriptor in keyword form (which you cannot use explicitly when calling the functions, as doing so throws a "x takes no keyword arguments" error), but mostly, what is the slash doing there?

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
Patrick Dennis
  • 323
  • 1
  • 7
  • 1
    Not an exact duplicate, but similar: https://stackoverflow.com/questions/24735311/python-what-does-the-slash-mean-in-the-output-of-helprange - `help()` displays the method signature, the documenation uses a different notation. – mata Dec 20 '17 at 15:27
  • So, the forward slash means, "all of the parameters to my left are positional-only, despite the fact that certain optional parameters having a default value might appear to be formatted as keyword parameters." ? – Patrick Dennis Dec 20 '17 at 22:49

1 Answers1

2

[Adding a bit to the linked answer...]

In Python3, documentation of optional args in signatures was changed from brackets, as in '[, start]' (with the default hopefully given in the docstring) to directly giving the default, as in 'start=0'. Sometime later (perhaps 3.4), '/' was (gradually) added to the signature of C-coded functions that do not allow passing an argument by keyword. Before this, there was no easy way to discover the fact without trial and exception. (I believe that there are a few optional args that do not have a default. These have to continue with brackets.)

None of this has anything to do with IDLE, which prints help() output as received. That is why I removed the tag. However, IDLE for current 3.6 and 3.7 adds the following to tooltips when the signature contains '/'.

['/' marks preceding arguments as positional-only]

I don't know if help() should do the same.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52