dlib icon indicating copy to clipboard operation
dlib copied to clipboard

Don't use __code__ to detect Python callable object

Open buckle2000 opened this issue 5 years ago • 3 comments

Expected Behavior

dlib.find_max_global (Python) should work on every callable object.

Current Behavior

It only works on objects with attribute __code__.

Steps to Reproduce

import dlib
from functools import partial
def f(arg0):
    return 0
dlib.find_max_global(partial(f, 2), [0.], [1.], 100)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-112-da98f75572a0> in <module>
----> 1 dlib.find_max_global(partial(f, 2), [0.], [1.], 100)

AttributeError: 'functools.partial' object has no attribute '__code__'
  • Version: dlib==19.19.0 (Python package)
  • Where did you get dlib: pip/pypi
  • Platform: Linux 5.0.0-38-generic #41-Ubuntu
  • Compiler: gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1)

buckle2000 avatar Mar 01 '20 17:03 buckle2000

Suggestion: https://docs.python.org/3/library/functions.html#callable

buckle2000 avatar Mar 01 '20 19:03 buckle2000

That would be cool. You should submit a PR :)

davisking avatar Mar 02 '20 01:03 davisking

But I don't know C++ :face_with_head_bandage:

buckle2000 avatar Apr 30 '20 03:04 buckle2000