GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug]: Item assignment and deletion on a sequence without `sq_ass_item` raise `TypeError` before converting an index key · Issue #1255 · oracle/graalpython

[Bug]: Item assignment and deletion on a sequence without sq_ass_item raise TypeError before converting an index key #1255

New issue
Copy link
New issue
Copy link
Open
#1267
Open
[Bug]: Item assignment and deletion on a sequence without sq_ass_item raise TypeError before converting an index key#1255
#1267
Copy link
Labels
bugSomething isn't workingSomething isn't working

Description

@jseop-lim
jseop-lim
opened on Oct 31, 2026
Issue body actions

Describe the bug

obj[key] = value and del obj[key] on a type that has sequence slots but no sq_ass_item (tuple, str, bytes, range, frozenset, a plain class) raise TypeError without calling key.__index__(). CPython converts the key first, so an exception from __index__, or IndexError for an oversized int, is raised instead of the TypeError.

Operating system

macOS

CPU architecture

ARM64

GraalPy version

master a3009f9 (Python 3.13.14); also reproduced on 25.0.2 (Python 3.12.8) and 25.4.4.1.1 (Python 3.13.14)

JDK version

No response

Context configuration

No response

Steps to reproduce

import operator

class RaisingIndex:
    def __index__(self):
        raise ZeroDivisionError

for f, args in [(operator.setitem, ((), RaisingIndex(), 0)),
                (operator.delitem, ('', RaisingIndex())),
                (operator.setitem, ('', 2**100, 0))]:
    try:
        f(*args)
    except Exception as e:
        print(type(e).__name__, e)

GraalPy master a3009f9:

TypeError 'tuple(EmptySequenceStorage[])' object does not support item assignment
TypeError '' object does not support item deletion
TypeError '' object does not support item assignment

Expected behavior

CPython 3.13.14 (same on 3.12.13):

ZeroDivisionError 
ZeroDivisionError 
IndexError cannot fit 'int' into an index-sized integer

Stack trace

Additional context

The statements t[RaisingIndex()] = 0 and del s[RaisingIndex()] take the same path. Types without sequence slots (int, object, types.GenericAlias) and non-index keys raise TypeError on both.

Root Cause

PyObjectSetItemGeneric converts the key with __index__ only in the specializations guarded by slots.sq_ass_item() != null; any other type falls into the @Fallback that raises TypeError (PyObjectSetItem.java#L125-L139), and PyObjectDelItemGeneric does the same (PyObjectDelItem.java#L118-L132). CPython's PyObject_SetItem and PyObject_DelItem convert an index key whenever the type has tp_as_sequence, before PySequence_SetItem / PySequence_DelItem look for sq_ass_item (abstract.c#L237-L252, #L271-L286).

Fix Suggestion

Add a specialization for mp_ass_subscript == null, sq_ass_item == null and slots.has_as_sequence() to both nodes that runs PyNumberAsSizeNode.executeExact(..., IndexError) on an index key before raising the existing TypeError.

Activity

  1. jseop-lim
    added
    bugSomething isn't workingSomething isn't working
    on Oct 31, 2026
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

    bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.