Ah, that's more or less what you now did :)  Except you raise an error instead of a warning. LGTM