mono/mono · error · TypeError
Must supply a non-negative int.
Error message
Must supply a non-negative int.
What it means
Raised by ArgumentsIterator.__getitem__ when the indexing key is not an int. The function-argument-type iterator only supports integer indexing; a non-int key (slice, str, None) hits the first guard before any bounds checks and raises TypeError. The inline FIXME notes slice support is intentionally unimplemented.
Source
Thrown at mono/tools/offsets-tool/clang/cindex.py:2210
The returned object is iterable and indexable. Each item in the
container is a Type instance.
"""
class ArgumentsIterator(collections_abc.Sequence):
def __init__(self, parent):
self.parent = parent
self.length = None
def __len__(self):
if self.length is None:
self.length = conf.lib.clang_getNumArgTypes(self.parent)
return self.length
def __getitem__(self, key):
# FIXME Support slice objects.
if not isinstance(key, int):
raise TypeError("Must supply a non-negative int.")
if key < 0:
raise IndexError("Only non-negative indexes are accepted.")
if key >= len(self):
raise IndexError("Index greater than container length: "
"%d > %d" % ( key, len(self) ))
result = conf.lib.clang_getArgType(self.parent, key)
if result.kind == TypeKind.INVALID:
raise IndexError("Argument could not be retrieved.")
return result
assert self.kind == TypeKind.FUNCTIONPROTO
return ArgumentsIterator(self)
@propertyView on GitHub (pinned to 0f53e9e151)
Solutions
- Index with a plain Python int (0 <= i < len(iterator)); iterate via 'for i in range(len(...))' or enumerate.
- If you need a sub-range, build it manually: [iterator[i] for i in range(start, end)].
- If holding a numpy/typed integer, cast with int(...) before indexing.
- Avoid slice syntax until the FIXME is resolved upstream.
Example fix
# before args = func_type.argument_types[0:2] # TypeError: Must supply a non-negative int. # after it = func_type.argument_types args = [it[i] for i in range(0, min(2, len(it)))]
Defensive patterns
Strategy: type-guard
Validate before calling
def arg_at(it, i):
if not isinstance(i, int): raise TypeError('index must be int')
return it[i] Type guard
def isIntIndex(k): return isinstance(k, int) and not isinstance(k, bool)
Prevention
- Index the iterator only with plain ints from range(len(...)).
- Never use slice syntax (unsupported, per the FIXME).
- Cast numpy/typed ints with int(...) first.
When it happens
Trigger: Indexing a function Type's argument iterator with anything other than an int — e.g. func_type.argument_types[0:2] (slice), func_type.argument_types['name'], or iterating with a non-integer accessor. The 'Must supply a non-negative int.' guard fires before the negative/out-of-range checks.
Common situations: Treating the iterator like a list and using slice syntax expecting a sub-list. Passing a numpy integer or other int-like object whose type is not literally int (isinstance(np.int64(0), int) is False). Scripting argument traversal with a loop variable that is accidentally a string.
Related errors
- Only non-negative indexes are accepted.
- Index greater than container length: %d > %d
- Argument could not be retrieved.
- Cannot convert '{}' to '{}'
- Invalid format options
AI-assisted analysis of mono/mono@0f53e9e151 (2026-08-13).
Data as JSON: /api/errors/fced2ed7cb2ebf00.
Report an issue: GitHub.