Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I was wondering what is the convention for return default types for python functions for e.g the below should Official return False or None, should Name return '' or None by default. What does Python recommend?

class Foo(object):

    def Official(self):
        """
        Flag to state if something is official e.g False / True
        :rtype: bool
        """
        return None

    def Name(self):
       """
       :rtype: str
       """
       return None
share|improve this question

closed as off-topic by jonrsharpe, syb0rg, Lyle's Mug, Donald.McLean, 200_success May 25 '14 at 6:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must involve real code that you own or maintain. Questions seeking an explanation of someone else's code are off-topic. Pseudocode, hypothetical code, or stub code should be replaced by a concrete example." – Lyle's Mug, Donald.McLean, 200_success
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Is this an abstract class, where subclasses are expected to override these methods? –  Anonymous May 24 '14 at 19:28
1  
maybe ask python what it recommends, a question such as What does Python recommend? begs for an answer of did you google this? this doesn't even look like production code, please read the help section about On-Topic Questions specifically Is it actual code from a project rather than pseudo-code or example code? –  Lyle's Mug May 25 '14 at 4:11

2 Answers 2

If those methods are supposed to be implemented in sub-classes inheriting from Foo, they should simply:

raise NotImplementedError

From the documentation:

In user defined base classes, abstract methods should raise [NotImplementedError] when they require derived classes to override the method.

share|improve this answer

I'm not aware of any language level conventions about this (which doesn't mean they don't exist, but I'd be surprised).

I think it's kind of impossible to make strong recommendations about your Foo class without knowing more of its context. Even with more context though, I think these sorts of questions often boil down to judgement and personal taste. And project-level conventions. If I was implementing your Foo, I'd probably have official return True/False and name return an empty string -- the empty string at least provides information about the type expected.

share|improve this answer
    
Cool thanks for the response I got a feeling your right its all about judgement and personal taste. Just trying to persist some consistency is probably the most important part –  user1741339 May 24 '14 at 19:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.