Skip to content Skip to sidebar Skip to footer

Python Builds Ok Even With Typos In The Code?

(note: I'm new to Python) I had a typo in a function call, and the project built, but crashed at runtime, when hitting the function call with the typo. Is this normal?! Shouldn't

Solution 1:

Actually PyLint will detect that, so if you're using Eclipse with PyDev plug-in, it will mark line with foe() as error.

PyDev can currently find:

  • Undefined variables
  • Undefined variable from import
  • Unused variables
  • Unused imports
  • Unused wild imports
  • Duplicated signatures
  • Import redefinition
  • Unresolved imports
  • No 'self' token declared in a class method
  • Mixing indentation with tabs and spaces
  • Bad indentation (incorrect number of spaces when indenting).

Screenshot of the OP's code parsed by PyLint in PyDev

Solution 2:

No it can't detect that.

It is dynamic and interpreted. You could actually add functions to classes at runtime - or import modules - so it can't easily detect if the function exists or not.

Solution 3:

Python is not "built", in the same way as C is. Functions can be created on the fly in Python. Think of def foo(): as adding an entry foo in a table of functions. When you call a function, Python looks up that function name in the table. If it's not there, you get a runtime error. This is by design. You'll still get error messages, although they will be when the unknown function is actually called.

Solution 4:

Python does not compile until you run the program. So it's hard to talk about "compile-time".

Solution 5:

You must use third party tool to check so called compilation errors. Look at this question (and answers) and PyChecker or PyLint.

Post a Comment for "Python Builds Ok Even With Typos In The Code?"