How To Return None¶
PEP-8 offers guidance on how to
return None (“Be consistent in return statements. […]”), which can be
slightly extended into the following rules of thumb:
If a function only returns
None, only “bare returns” (areturnstatement with no return expression or value) should be used, and only to return early.If a function returns
Optional[...], then all code paths should have a non-barereturnstatement.