[Python-projects] Flag missing else: clauses?

skip at pobox.com skip at pobox.com
Fri Mar 14 23:10:21 CET 2008


Can I get pylint to flag missing else clauses in if statements?  For example
(snippet from daemonize.sf.net which just reminded me I wanted to ask this
awhile ago):

    process_id = os.fork()
    if process_id < 0:
        sys.exit(1)
    elif process_id != 0:
        sys.exit(0)
    # This is the child process.  Continue.

This is perfectly fine code, but I run into code all the time where the
missing else: clause is a bug.

    process_id = os.fork()
    if process_id < 0:
        sys.exit(1)
    elif process_id != 0:
        sys.exit(0)
    else:
        # This is the child process.  Continue.
        pass

Thanks,

-- 
Skip Montanaro - skip at pobox.com - http://www.webfast.com/~skip/


More information about the Python-Projects mailing list