Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to designate unreachable python code

Tags:

python

What's the pythonic way to designate unreachable code in python as in:

gender = readFromDB(...) # either 'm' or 'f'
if gender == 'm':
    greeting = 'Mr.'
elif gender == 'f':
    greeting = 'Ms.'
else:
    # What should this line say?
like image 559
phihag Avatar asked May 02 '09 18:05

phihag


People also ask

What to do if code is unreachable in Python?

You should just remove the return True line, and instead of print (result) , return result . That will be True if the matrix is square AND symmetric, and False if it's square and NOT symmetric.

Why does it say code is unreachable in Python?

In computer programming, unreachable code is part of the source code of a program which can never be executed because there exists no control flow path to the code from the rest of the program.

What is code unreachable Pylance?

Any code block that is guarded by a conditional checks for Python 2 will not be analyzed. So while the code block may run on your server, it is treated as unreachable from the perspective of the static code analyzer in Pylance.


1 Answers

raise ValueError('invalid gender %r' % gender)
like image 118
Dave Avatar answered Sep 30 '22 04:09

Dave