Note to maintainers: this might be useful as a utils method, we use this check internally in a few places.