Repository navigation
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement
Description
| BPO | 9896 |
|---|---|
| Nosy | @rhettinger, @terryjreedy, @mdickinson, @pitrou, @ezio-melotti, @merwok, @durban, @smarnach |
| Files |
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 = <Date 2011-11-05.19:19:10.729>
created_at = <Date 2010-09-18.18:39:25.954>
labels = ['interpreter-core', 'type-feature']
title = 'Introspectable range objects'
updated_at = <Date 2011-11-05.19:19:10.728>
user = 'https://github.com/durban'bugs.python.org fields:
activity = <Date 2011-11-05.19:19:10.728>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2011-11-05.19:19:10.729>
closer = 'python-dev'
components = ['Interpreter Core']
creation = <Date 2010-09-18.18:39:25.954>
creator = 'daniel.urban'
dependencies = []
files = ['18922', '21692', '21733']
hgrepos = []
issue_num = 9896
keywords = ['patch']
message_count = 13.0
messages = ['116824', '116836', '116839', '116846', '116853', '117330', '117366', '133921', '134067', '134102', '145712', '147096', '147104']
nosy_count = 9.0
nosy_names = ['rhettinger', 'terry.reedy', 'mark.dickinson', 'pitrou', 'ezio.melotti', 'eric.araujo', 'daniel.urban', 'python-dev', 'smarnach']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue9896'
versions = ['Python 3.3']Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement
Activity
durban commentedon Sep 18, 2010
The attached patch adds the start, stop and step members to range objects, corresponding the contructor arguments. The patch also include tests and documentation changes.
rhettinger commentedon Sep 18, 2010
I don't see anything wrong with this idea, but I don't really see a need for it either. AFAICT, this has never been requested in the 20 years that range() has been in Python. This is probably YAGNI. It may also be in violation of the language moratorium (it's one more thing that other implementations would have to mirror).
rhettinger commentedon Sep 18, 2010
One other thought. If there is a perceived need, I would rather an alternate approach that unifies a language a bit by letting range() expose its arguments as a slice and modify its input to accept a slice.
BreamoreBoy commentedon Sep 19, 2010
What is the use case for this?
durban commentedon Sep 19, 2010
The basic idea was, that in Python almost everything is introspectable, so why range objects aren't. It was pretty straightforward to implement it, so I've done it (actually when I was working on rangeobject.c, I was surprised to see that these members aren't available from python code).
But if this isn't needed, I'm absolutely ok with that. I think this would be a nice to have feature, but of course not necessary. Also, if it violates the moratorium (I don't know), then of course this sould be at least postponed.
terryjreedy commentedon Sep 24, 2010
Range objects are new in 3.0; they supersede 2.x xrange objects, which are perhaps 10 years old. I do not remember that xrange objects had such attributes. On the other hand, I believe there were requests.
The request, with either implementation, seems reasonable in that range objects could be regarded as iterable slice objects. The differences are that range objects have __getitem__, __iter__, and __reversed__ special methods while slice objects have start, stop, and stop real-only attributes and the indices method. (I could not really understand the last from the doc; I had to experiment.) Starting fresh, we might do with just one class instead of two.
I guess this makes me +0.3 at the moment.
pitrou commentedon Sep 25, 2010
This sounds like an obscure complication to me. A range is not a slice and I don't see the point of trying to bridge both concepts. It is even more YAGNI than the original request.
durban commentedon Apr 17, 2011
Now that the moratorium has already ended, I'll try again. I've updated the patch.
It seems, that this idea has already came up in the past: Guido in msg70525 said: "I also think ranges should be introspectable, exposing their start, stop and step values just like slice objects."
A possible use case: the range slicing logic is quite complex (with a lot of corner cases). It would be good, if this logic would be accessible from Python code, for example to compute a slice of a slice-like-thing. Currently slicing a range object returns another range object, but there is no way to determine the bounds of this new object.
merwok commentedon Apr 19, 2011
Looks good, apart from the use of assertEquals (deprecated in favor of assertEqual). I’d also remove “merely” from the doc addition.
durban commentedon Apr 19, 2011
Thanks, I've corrected my patch.
ezio-melotti commentedon Oct 17, 2011
See also bpo-13200.
merwok commentedon Nov 5, 2011
I think this is ready for commit.
python-dev commentedon Nov 5, 2011
New changeset 4643be424293 by Benjamin Peterson in branch 'default':
add introspection to range objects (closes bpo-9896)
http://hg.python.org/cpython/rev/4643be424293