> for example when `isinstance(scope, er.Instance)`

No this is happening at a different place (`find_name`). Maybe it might be better to move that to `get_names_of_scope`... But I'm not sure.

So, you'll be fine just using `next(get_names_of_scope(scope), None)` or something like this.