-
Notifications
You must be signed in to change notification settings - Fork 95
Add Slice function for range type #83
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
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unittests in here
https://github.com/go-python/gpython/blob/master/py/tests/range.py
6240240
to
6ee9326
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Do you have any suggestion? @ncw
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@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