Skip to content

useless-return and explicit "return None" #2300

Closed
@The-Compiler

Description

Similarly to what's already been said on the mailinglist, I don't think an explicit return None should count as useless return.

Consider this class:

class PseudoLayout(QLayout):

    # [...]

    def count(self) -> int:
        return 0

    def itemAt(self, _pos) -> Optional[QWidget]:
        return None

Here, I do need to override itemAt (because PyQt or rather C++ tells me to), but my layout never actually has any items in it, so I always want to return None.

Sure, from Python's perspective, I might as well just put pass there and rely on the implicit return None, but IMHO this is a case of "explicit is better than implicit". The function is clearly intended to return something (and not just there for it's side effects), so IMHO, there should be an explicit return here.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions