Add Slice function for range type#83
Conversation
da3b6e8 to
14646a7
Compare
Codecov Report
@@ Coverage Diff @@
## master #83 +/- ##
==========================================
+ Coverage 68.84% 68.98% +0.13%
==========================================
Files 59 59
Lines 10545 10588 +43
==========================================
+ Hits 7260 7304 +44
+ Misses 2775 2774 -1
Partials 510 510
Continue to review full report at Codecov.
|
570ec8e to
b39bd4e
Compare
corona10
left a comment
There was a problem hiding this comment.
Please add unittests in here
https://github.com/go-python/gpython/blob/master/py/tests/range.py
6240240 to
6ee9326
Compare
|
CPython (v3.7.4) has an additional type check that raises an exception on wrong types like: class C:
def __index__(self):
return 1
r = range(10)
assert len(r[:C()]) == 1
# len(r[:1.1]) -> Exception |
|
@HyeockJinKim Please rebase the PR and reflect @Tim-St 's review. |
corona10
left a comment
There was a problem hiding this comment.
Please follow the comment I left.
Crate a new range object by calculating start, stop, and step when slice is entered as argument to the __getitem__ function of the range Fixes go-python#77
If __index__ is defined when class is used as index value, __index__ value is used.
6ee9326 to
2da2efa
Compare
|
@HyeockJinKim For example: class C:
def __index__(self):
return "abc"
r[:C()]Should raise Maybe it would be good to first call Also the following should throw an Exception like in CPython: But I think that is quite much work to implement, so we could also just handle this as a new issue. The following code results are different in CPython (sorry, I didn't find this before): r = range(10)
r[-2::-2] # r[-2::2] is ok
r[-2::-1]
r[:-2:-1]
r[-2:-2:-2] |
Crate a new range object by calculating start,
stop, and step when slice is entered as argument
to the getitem function of the range
Fixes #77