24 Jul

Have you ever run into a problem where your favorite Python IDE can't determine the type of a variable, and thus you get no auto-completion? There is a built-in function in Python called isInstance(your_variable, type_of_variable) that is designed to compare a variable to a class type, and return true or false. However, just the presence of this function will give many IDEs all the information they need to determine the type of your variable, and thus give you better auto-completion.

For example, imagine you had a function that returned a gtk.Window.
MyWindow = GetMyWindow()

Most IDEs would not correctly determine the type of MyWindow. To solve this, try the following code:

MyWindow = GetMyWindow()
isInstance(MyWindow, gtk.Window)

There are many articles that point out the dangers of using isInstance, however if you are simply using it like my example, it shouldn't cause any problems.