use isinstance(...) instead of type(...)

Just a small code improvement in case somebody decides to sub-class
Connection.