Jon.H
Jon.H

Reputation: 842

Why return nothing in class method?

I've recently started working at a company doing work in Python, and in their code they have a class which defines a handful of functions that do nothing, and return nothing. Code that is pretty much exactly

...
...
def foo(self):
    return

I'm really confused as to why anyone would do that, and my manager is not around for me to ask. Would one do this for the sake of abstraction for child classes? A signal that the function will be overridden in the future? The class I'm looking at in particular inherits from a base class that does not contain any of the functions that are returning nothing, so I know that at least this class isn't doing some kind of weird function overriding.

Upvotes: 0

Views: 857

Answers (2)

mgilson
mgilson

Reputation: 309821

Sometimes, if a class is meant to be used interchangeably with another class in the API, it can make sense to provide functions that don't do much (or anything). Depending on the API though, I would typically expect these functions to return something like NotImplemented.

Or, maybe somebody didn't get enough sleep the night before and forgot what they were typing ... or got called away to a meeting without finishing what they were working on ...

Ultimately, nobody can know the actual reason without having a good knowledge of the code you're working with. Basically -- I'd wait for your boss or a co-worker to come around and ask.

Upvotes: 5

Tyler Durden
Tyler Durden

Reputation: 11522

If the functions have meaningful names, then it could be a skeleton for future intended functionality.

Upvotes: 4

Related Questions