test: convert docs into type annotations
Summary:
Rather than having function types exist as documentation, make them type annotations, which enables more mypy checking.
This is a backport of core#22092
Test Plan: ninja check-functional
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D10952