Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nit for builtin sum doc #42348

Closed
daishiharada mannequin opened this issue Sep 7, 2005 · 7 comments
Closed

nit for builtin sum doc #42348

daishiharada mannequin opened this issue Sep 7, 2005 · 7 comments
Assignees

Comments

@daishiharada
Copy link
Mannequin

daishiharada mannequin commented Sep 7, 2005

BPO 1283491
Nosy @birkenfeld, @birkenfeld, @rhettinger

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2006-10-12.12:33:19.000>
created_at = <Date 2005-09-07.00:18:50.000>
labels = []
title = 'nit for builtin sum doc'
updated_at = <Date 2006-10-12.12:33:19.000>
user = 'https://bugs.python.org/daishiharada'

bugs.python.org fields:

activity = <Date 2006-10-12.12:33:19.000>
actor = 'georg.brandl'
assignee = 'georg.brandl'
closed = True
closed_date = None
closer = None
components = ['None']
creation = <Date 2005-09-07.00:18:50.000>
creator = 'daishiharada'
dependencies = []
files = []
hgrepos = []
issue_num = 1283491
keywords = []
message_count = 7.0
messages = ['26221', '26222', '26223', '26224', '26225', '26226', '26227']
nosy_count = 4.0
nosy_names = ['georg.brandl', 'georg.brandl', 'rhettinger', 'daishiharada']
pr_nums = []
priority = 'low'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1283491'
versions = []

@daishiharada
Copy link
Mannequin Author

daishiharada mannequin commented Sep 7, 2005

the docstring signature for sum in bltinmodule.c
should be changed from:
sum(sequence, start=0)
to:
sum(sequence[, start])
to reflect the current implementation in builtin_sum.

(or else the implementation should be changed
to accept kwargs.)

@daishiharada daishiharada mannequin closed this as completed Sep 7, 2005
@daishiharada daishiharada mannequin assigned birkenfeld Sep 7, 2005
@daishiharada daishiharada mannequin closed this as completed Sep 7, 2005
@daishiharada daishiharada mannequin assigned birkenfeld Sep 7, 2005
@rhettinger
Copy link
Contributor

Logged In: YES
user_id=80475

While the proposed change is technically correct, I find the
original to be more informative.

@daishiharada
Copy link
Mannequin Author

daishiharada mannequin commented Sep 7, 2005

Logged In: YES
user_id=493197

This is relatively minor so I don't mean
to push particularly hard, but I'd like to
at least show how the docstring made
me stray:

>>> sum([x] for x in xrange(10))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for +: 'int' and 'list'
>>> help(sum)
Help on built-in function sum in module __builtin__:
sum(...)
    sum(sequence, start=0) -> value
    
    Returns the sum of a sequence of numbers (NOT strings) plus the value
    of parameter 'start'.  When the sequence is empty, returns start.
>>> sum([x] for x in xrange(10), start=[])
  File "<stdin>", line 1
SyntaxError: invalid syntax

# The problem above is orthogonal to the issue in this bug,
# but I wonder if at some point we'll be able to write such?

>>> sum(([x] for x in xrange(10)), start=[])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: sum() takes no keyword arguments

# examine lib docs, which give the signature:
# sum( sequence[, start])

>>> sum(([x] for x in xrange(10)), [])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> 

# examine bltinmodule.c to confirm that
# sum doesn't accept kwargs.

1 similar comment
@daishiharada
Copy link
Mannequin Author

daishiharada mannequin commented Sep 7, 2005

Logged In: YES
user_id=493197

This is relatively minor so I don't mean
to push particularly hard, but I'd like to
at least show how the docstring made
me stray:

>>> sum([x] for x in xrange(10))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for +: 'int' and 'list'
>>> help(sum)
Help on built-in function sum in module __builtin__:
sum(...)
    sum(sequence, start=0) -> value
    
    Returns the sum of a sequence of numbers (NOT strings) plus the value
    of parameter 'start'.  When the sequence is empty, returns start.
>>> sum([x] for x in xrange(10), start=[])
  File "<stdin>", line 1
SyntaxError: invalid syntax

# The problem above is orthogonal to the issue in this bug,
# but I wonder if at some point we'll be able to write such?

>>> sum(([x] for x in xrange(10)), start=[])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: sum() takes no keyword arguments

# examine lib docs, which give the signature:
# sum( sequence[, start])

>>> sum(([x] for x in xrange(10)), [])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> 

# examine bltinmodule.c to confirm that
# sum doesn't accept kwargs.

@rhettinger
Copy link
Contributor

Logged In: YES
user_id=80475

"""
>>> sum([x] for x in xrange(10), start=[])
  File "<stdin>", line 1
SyntaxError: invalid syntax

# The problem above is orthogonal to the issue in this bug,
# but I wonder if at some point we'll be able to write such?
"""

FYI, the answer is no. The requirement for parenthesis
cannot change. To see why, parse this: f(g(t) for t in a,
b).

@birkenfeld
Copy link
Member

Logged In: YES
user_id=1188172

If we change the function signature in the docstring, we
must include the "defaults to 0" somewhere.

@birkenfeld
Copy link
Member

Logged In: YES
user_id=849994

Fixed in rev. 52315.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants