Type hints fixes

Contains a load of fixes about template generation, unused variables/classes (please check the `Setting` and `Settings` related commits) and fixes docblocks all around the codebase.