As a matter of fact, after seeing a little more code, I don't think we need to *see* if n is an int or not so early. On line 950, there's a line that was explicitly changing n to int.
`n = int(n)`
Just replacing this line with
`n = as_int(n)`
is doing the job perfectly. I think that's the better way of doing this since we are changing the very line with the faulty logic.