May 032012

Because Python isn’t strongly typed, sometimes PyDev doesn’t know what type a variable is – and therefore it cannot give you accurate code completions. Here’s how to make that better.

In simpler situations, PyDev works very well. For example:

emp = Employee()

Typing ’emp.’ will get you a good autocomplete.

Now, let’s say you have something like this:

emp = something.find_employee("dave")

Then ’emp.’ won’t get you anything – PyDev doesn’t necessarily know what type is being returned.

If you use python’s assert method:

emp = something.find_employee("dave")
assert isinstance(emp, Employee)

PyDev now knows what type the variable is, and you’ll get more effective code completions.

When running in production, you can pass the “-O” flag to the interpreter, and it will ignore the assert statements.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>