I’ve tried this:
if hero.distanceTo(target) < 5:
# Put your attack code here
# If cleave is ready, then cleave target
# else, just attack target!
This code is not part of the function.
enemy = hero.findNearestEnemy()
# Note that inside cleaveWhenClose, we refer to the enemy as target.
[Please be polite]