Actual Fix to Issue #2795

I apologize about my previous solution.  It worked on many of test
cases, but I forgot to test it out on the original source code and as a
result my personal updates interfered and I provided a non-solution as
a solution.  This change,  however, does in fact fix the issue, though
it is slightly hacky, due to the use of isinstance().  I hope a better
one exists and I am looking into it, but this definitely solves the
issue.