Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Handle the return of non-integer value in __index__ function #96

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

Closed
HyeockJinKim opened this issue Sep 28, 2019 · 1 comment · Fixed by #97
Closed

Handle the return of non-integer value in __index__ function #96

HyeockJinKim opened this issue Sep 28, 2019 · 1 comment · Fixed by #97
Labels
bug Something isn't working Contributhon2019

Comments

@HyeockJinKim
Copy link
Contributor

An error should occur when returning a non-integer value from index.

Expected result (cpython)

>>> class C:
...     def __index__(self):
...         return 'a'
... 
>>> c = C()
>>> a = [1, 2 ,4]
>>> a[c]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __index__ returned non-int (type str)

Actual result (gpython)

>>> class C:
...     def __index__(self):
...         return 'a'
... 
>>> c = C()
>>> a = [1, 2, 4]
>>> a[c]
1
HyeockJinKim added a commit to HyeockJinKim/gpython that referenced this issue Sep 28, 2019
Generate TypeError when __index__ return
non-integer value

Fixes go-python#96
@ncw ncw added bug Something isn't working Contributhon2019 labels Sep 28, 2019
@ncw
Copy link
Collaborator

ncw commented Sep 28, 2019

Well spotted :-)

HyeockJinKim added a commit to HyeockJinKim/gpython that referenced this issue Sep 29, 2019
Generate TypeError when __index__ return
non-integer value

Fixes go-python#96
@ncw ncw closed this as completed in #97 Oct 1, 2019
ncw pushed a commit that referenced this issue Oct 1, 2019
Generate TypeError when __index__ return non-integer value

* Handle error of slice in range type
  * When an error occurs, the error is returned and
  * when the value is none the slice's values have a default value.
* Add tests for __index__
* Add tests for __index__ function
* Add tests for __index__ in list, tuple, string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Contributhon2019
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants