[WIP] Use the right type for self in methods and remove obsoleted items.
Fixes #7411, #10615.