classification
Title: xmlrpc.client documentation multicall example missleading for division behaviour of python3
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: ber, docs@python, ezio.melotti, python-dev
Priority: normal Keywords:

Created on 2013-06-19 21:03 by ber, last changed 2013-08-08 12:47 by ezio.melotti. This issue is now closed.

Messages (5)
msg191495 - (view) Author: Bernhard Reiter (ber) (Python committer) Date: 2013-06-19 21:03
http://docs.python.org/3.4/library/xmlrpc.client.html as of 2013-06-19 20:35 UTC
has a divide example and the output can misslead the learning reader
towards the new behaviour of python3 with the '/' binary operator for division.

server code:
  def divide(x, y):
    return x/y
client code:
  multicall.divide(7,3)
[..]
  print("7+3=%d, 7-3=%d, 7*3=%d, 7/3=%d" % tuple(result))

The client call results into:
  python3 client.py 
7+3=10, 7-3=4, 7*3=21, 7/3=2

This is missleading because '7/3' is now resulting to a float in python3 (see PEP238).The example probably was copied over from the python2 documentation
where '7/3' result to int. The implicit conversion from float to int is done
in the string formatting.

Proposal replace the print line with
  print("7+3=%d, 7-3=%d, 7*3=%d, 7/3=%g" % tuple(result))
to get 
  7+3=10, 7-3=4, 7*3=21, 7/3=2.33333
or
  print(repr(tuple(result)))
to get
(10, 4, 21, 2.3333333333333335)
msg191552 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-06-21 01:40
New changeset 2a3bc6eb2e13 by Andrew Kuchling in branch '3.3':
Closes #18267: use floor division in code example
http://hg.python.org/cpython/rev/2a3bc6eb2e13
msg191732 - (view) Author: Bernhard Reiter (ber) (Python committer) Date: 2013-06-23 21:09
Andrew,
thanks for caring!

Seeing your fix 2a3bc6eb2e13 I believe it does not fully resolv the issue.
Now the code reads
 "return x // y"
  "multicall.divide(7,3)"
and the client prints
 "7/3=2"

I think you probably should change "7/3=" to "7//3=" in the client code as well
to be instructive to learners.

By the way: your change also introduced whitespace around the operator. Now it is the only one out of the four. I guess they should be consistent.
msg194666 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-08-08 12:46
New changeset 38d341ef28b3 by Ezio Melotti in branch '3.3':
#18267: make whitespace consistent and fix an operator.
http://hg.python.org/cpython/rev/38d341ef28b3

New changeset 9875410ed390 by Ezio Melotti in branch 'default':
#18267: merge with 3.3.
http://hg.python.org/cpython/rev/9875410ed390
msg194667 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-08-08 12:47
Fixed, thanks for the report!
History
Date User Action Args
2013-08-08 12:47:03ezio.melottisetstatus: open -> closed

type: enhancement
assignee: docs@python -> ezio.melotti
versions: - Python 3.1, Python 3.2
nosy: + ezio.melotti

messages: + msg194667
resolution: fixed
2013-08-08 12:46:27python-devsetmessages: + msg194666
2013-06-23 21:09:23bersetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg191732
2013-06-21 01:40:25python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg191552

resolution: fixed
stage: resolved
2013-06-19 21:03:25bercreate