Assigning result of a function call, where the function has no return
82 except com_error as ex: # @UndefinedVariable
83 if ex.hresult == -2147352567:
84 msg = "Excel complained: \n %s" % ex.excepinfo[2]
85 msg = show_unlock_msg(msg) 86 raise Exception(msg)
87 raise
88
Assigning result of a function call, where the function has no return
76 xl_vbp = xl_wb.VBProject
77 if xl_vbp.Protection == 1:
78 msg = "The VBA-code in Excel is protected!"
79 msg = show_unlock_msg(msg) 80 raise Exception(msg)
81 return xl_vbp
82 except com_error as ex: # @UndefinedVariable
Description
An assignment is done on a function call but the inferred function doesn't return anything. While this is not an error in Python, it is a critical anti-pattern and can lead to unexpected bugs.
Bad practice
def square(number):
'''Returns the square of a number'''
number ** 2 # Forgot a `return` here
result = square(4)
Recommended
def square(number):
'''Returns the square of a number'''
return number ** 2
result = square(4)