Skip to content

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

Description

@HyeockJinKim

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

Activity

  1. added a commit that references this issue on Sep 28, 2019
    e9ac43a
  2. ncw commented on Sep 28, 2019

    @ncw
    Collaborator

    Well spotted :-)

  3. added a commit that references this issue on Sep 29, 2019
    ac63290
  4. added a commit that references this issue on Oct 1, 2019
    36da816
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions