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

Misleading information about slice assignment in docs #62139

Open
stefanchrobot mannequin opened this issue May 8, 2013 · 2 comments
Open

Misleading information about slice assignment in docs #62139

stefanchrobot mannequin opened this issue May 8, 2013 · 2 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@stefanchrobot
Copy link
Mannequin

stefanchrobot mannequin commented May 8, 2013

BPO 17939
Nosy @terryjreedy, @ezio-melotti

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 = None
closed_at = None
created_at = <Date 2013-05-08.21:31:39.955>
labels = ['type-feature', '3.8', '3.9', '3.10', 'docs']
title = 'Misleading information about slice assignment in docs'
updated_at = <Date 2020-11-17.15:23:56.125>
user = 'https://bugs.python.org/stefanchrobot'

bugs.python.org fields:

activity = <Date 2020-11-17.15:23:56.125>
actor = 'iritkatriel'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2013-05-08.21:31:39.955>
creator = 'stefanchrobot'
dependencies = []
files = []
hgrepos = []
issue_num = 17939
keywords = []
message_count = 2.0
messages = ['188738', '188870']
nosy_count = 4.0
nosy_names = ['terry.reedy', 'ezio.melotti', 'docs@python', 'stefanchrobot']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue17939'
versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

@stefanchrobot
Copy link
Mannequin Author

stefanchrobot mannequin commented May 8, 2013

http://docs.python.org/3/reference/simple_stmts.html#assignment-statements

The docs says:

"If the target is a slicing: The primary expression in the reference is evaluated. It should yield a mutable sequence object (such as a list). The assigned object should be a sequence object of the same type."

This seems wrong, because the assigned object can be any iterable:

a = [4, 5, 6]
a[0:0] = range(1, 4)
# a is now [1, 2, 3, 4, 5, 6]

@stefanchrobot stefanchrobot mannequin assigned docspython May 8, 2013
@stefanchrobot stefanchrobot mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels May 8, 2013
@terryjreedy
Copy link
Member

Since range objects have a known length, that example is not enough to show 'any iterable'. However, generators do not even have a __length_hint__ and they work too.

a = [1,2,3]
a[0:1] = (i for i in range(4))
print(a)
>>> 
[0, 1, 2, 3, 2, 3]

@iritkatriel iritkatriel added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Nov 17, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants