misc/collect.py: move out nested method to please linter