test_framework: improve the syntax of serialize() methods
Summary:
These changes do not affect behavior.
Don't unnecessarily initialize an empty bytes object before appending to it.
Don't use an intermediate variable before returning in trivial cases.
Add a few typehints when they are not obvious to the reader (e.g. when *string* actually means *bytes* because of python2 legacy)
Test Plan: ninja check-functional-extended
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D17835