using inspect to avoid indexing problem on py3