Fix typo introduced in 2fe9a71e
Use a factory function instead of static class method
Be more duck friendly when checking for non-None values
Fix all flake8 issues and add flake8 run to 'make tests'