Sometimes pythons dynamic typing system is confusing to understand why some things work. For example:
I'm looking for some clarification on the above question and some advice on how to generalise towards similar situations.
read_sql
is documented as taking a Connectable
object. Strictly speaking, that means it would be an instance of SqlAlchemy.engine.Connectable
or a subclass thereof, but the only thing that is important is that it behave like such an instance. Roughly speaking, you can pass anything that's "like" a Connectable
, in that, for example, tt provides a connect
method that takes the same kinds of arguments as sqlalchemy.engine.Connectable.connect
.
In other words, it's not the exact type that matters, but the interface to the type you pass. Python refers to this as duck typing: if an object looks like a duck and acts like a duck, it can be used by something that requires a duck, even if it's not, actually, a duck.