Allow any callable for adaptive functions and raise TypeError if not valid
Explanation of changes
Small change to the adaptive subroutine.
An instance check that checks if the adaptive_function
is indeed a FunctionType
is changed to a check if it is callable
. Also, A TypeError
is raised when the adaptive function is neither a BaseLearner
, nor is callable.
Motivation of changes
When using cython-compiled python code (as we do internally), the passed adaptive function (which is a cyfunction
instance) does not pass the instance check, since a cyfunction
is not a subclass of the FunctionType
. This causes the subroutine to pass silently (since no exception is raised when both checks fail).
This change allows for any callable to be passed (also objects that are callable, which potentially allows for a more powerfull interface too). To improve debugging, I've added the TypeError
- if it were present, it'd saved me some ours of debugging :)
Merge checklist
See also merge request guidelines
-
Merge request has been reviewed (in-depth by a knowledgeable contributor), and is approved by a project maintainer. -
New code is covered by unit tests (or N/A). -
New code is documented and docstrings use numpydoc format (or N/A). -
New functionality: considered making private instead of extending public API (or N/A). -
Public API changed: added @deprecated
(or N/A). -
Newly added/adjusted documentation and docstrings render properly (or N/A). -
Pipeline fix or dependency update: post in #software-for-developers
channel to mergemain
back in or update local packages (or N/A). -
Tested on hardware (or N/A). -
CHANGELOG.md
for breaking changes andAUTHORS.md
have been updated (or N/A). -
Windows tests in CI pipeline pass (manually triggered by maintainers before merging). - Maintainers do not hit Auto-merge, we need to actively check as manual tests do not block pipeline
For reference, the issues workflow is described in the contribution guidelines.