quora/qcore

get_original_fn() fails on objects with C impl

Closed this issue · 0 comments

We have this:

fn.original_fn = get_original_fn(fn.fn)

This assumes that it's okay to set .original_fn attribute on the fn item. However, that's not the case when the method's object (and, iirc, for the case of a function itself) is implemented in C/Cython.

Here's an example of the error raised:

    original_target = qcore.inspection.get_original_fn(outer_target)
  File "qcore/inspection.py", line 27, in qcore.inspection.get_original_fn
  File "qcore/inspection.py", line 36, in qcore.inspection.get_original_fn
AttributeError: 'method' object has no attribute 'original_fn'

A simple try/except should do the job, I think. I'll submit a patch.