Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: are there ways to detect missing () in method call?

Tags:

python

I want to call a method f(), but accidentally I just say f. Python3 mistakes this for a meaningless evaluation of a nonexisting variable, and therefore skips over my intended method call without any notice. Is there a way to override this default behavior and to get an error message? Either by forbidding dual use of an identifier as a method and as a variable, or by forbidding a meaningless statement consisting just of an identifier?

like image 938
Joachim W Avatar asked Jan 14 '23 18:01

Joachim W


1 Answers

It's valid syntax, so Python won't complain. You may want to consider some other tools, like pylint. Pylint would've reported:

W:  4,0: Statement seems to have no effect

If you simply did:

f

instead of:

f()

The only catch is the pylint can complain an awful lot out of the box. Make sure to create a config that is tolerant of your style.

like image 70
John Szakmeister Avatar answered Jan 30 '23 01:01

John Szakmeister