etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
782 stars 212 forks source link

allow any callable as argument to TreeStyle.set_layout_fn #562

Closed jfaccioni closed 1 year ago

jfaccioni commented 3 years ago

This PR allows any callable object to be set as the layout function of a TreeStyle object.

Currently, only objects whose type match types.FunctionType or types.MethodType are allowed. This behavior excludes otherwise valid Python callables, e.g. partial functions created with functools.partial, or any used-defined class that implements __call__, irrespective of whether the actual call would succeed or not.

The PR fixes this by using the callable built-in function for checking the layout function's type.