[Python-projects] Flag missing else: clauses?

Amaury Forgeot d'Arc amauryfa at gmail.com
Fri Mar 14 23:32:58 CET 2008


Hello,

On Fri, Mar 14, 2008 at 11:10 PM,  skip wrote:
>
>  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

Well, there are many places where an else: clause is not needed at all.
   if isinstance(message, unicode):
        message = message.encode('utf-8')
Do you want a pylint warning in every case?

BTW, os.fork() and other posix functions never return negative values
in Python. They raise exceptions...

-- 
Amaury Forgeot d'Arc


More information about the Python-Projects mailing list