#!/usr/bin/env python3 from array import array class SubclassedArray(array): def __getitem__(self, i): return 0 typecodes = ("I", "i", "Q", "q", "L", "l", "B", "b") # Floating point typecodes are tested separately to avoid a TypeError float_typecodes = ("f", "d") for tc in (typecodes, float_typecodes): for a_type in tc: a = array(a_type, range(10)) print(a) for b_type in tc: assert(a == SubclassedArray(b_type, a))