Detect naming typos (AttributeError) in function names

c.buhtz at posteo.jp c.buhtz at posteo.jp
Mon Nov 6 07:47:57 EST 2023


Hello,

I would like to know how to detect (e.g. via a linter) typos in function 
names imported from another module.

Let's assume this given Python code snippet.

import foo
foo.baR()

The package "foo" do contain a function named "bar()" (all lower case 
letters). The function "baR()" does not exist in "foo". This cause an 
AttributeError when run with a Python interpreter.

The described error is not detected in my IDE (Emacs with eglot, pylsp 
and flake8) and not by flake8 on the shell. Because the involved tools 
do not look inside the "foo" package if "baR()" really exist.

Can I fix this somehow?

I am aware that this would get detected by a unit test. That is the way 
I do prefer in most cases. But sometimes not all code segments are 
covered by tests. I'm more interested in using a linter or something 
else for that.

Kind
Christian


More information about the Python-list mailing list