Skip to content

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

Closed
@HyeockJinKim

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

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