2

What tools or techniques can help avoid bugs, especially silly mistakes such as typos, coding in Python and Django?

I know unit-testing every line of code is the "proper" way, but are there any shortcuts?

I know of pylint, but unfortunately it doesn't check Django ORM named parameters, where a typo can go unnoticed. Is there any tool that can handle this kind of bugs?

A colleague thought of an idea to gather smart statistics on tokens (for example about named parameters to functions...), and when a once-in-a-code-base token is encountered it is warned as possible typo. Do you know of any tool that does something similar?

Iftah
  • 9,512
  • 2
  • 33
  • 45

3 Answers3

2

Sorry I don't know if I understand you correctly,

But I think a good IDE has automatic code validation and some of them also work with Django. For example, there is a good python plugin for Eclipse called PYDEV. There is also a good IDE based on Eclipse/Pydev called Aptana Studio that you can try (it also has good support for editing HTML/JS/CSS).

This Question is also a very good comparison of all the Python IDE's.

Community
  • 1
  • 1
evotopid
  • 5,288
  • 2
  • 26
  • 41
2

pyflakes is a static analyser that will find undeclared variables (e.g. typos) and the like. plenty of editors have plugins that run pyflakes on the fly or on save. This is not a substitute for unit tests, but it can save a few unnecessary save-reload-run cycles

second
  • 28,029
  • 7
  • 75
  • 76
0

Thank you for your answers, I'll check these tools.

I wanted to share with you other ideas (none python/django specific):

  1. Assert conditions in code - but remove from production code.

  2. Run periodic checks on the data (eg. sending email to dev when found unexpected state) - in case a bug slips by it may be detected faster, before more data is corrupt (but alas after some of it is already corrupt).

  3. Make a single bottom-line test (perhaps simulating user input), that covers most of the program. It may catch exceptions and asserts and is may be easier to maintain than many tests.

Iftah
  • 9,512
  • 2
  • 33
  • 45