3 ms·
What are you referring to when you say you don't want types at runtime? Every Python object has a type and type-checks will be performed at runtime (e.g., "hell
by ptx 7y ago
What are you referring to when you say you don't want types at runtime? Every Python object has a type and type-checks will be performed at runtime (e.g., "hello" + 42).
- tomnipotent 7y agoDuck typing. A Python object doesn't have to have a specific type, just the attribute(s) you want. You'll find a lot of "hasattr(obj, x)" throughout any large Python code base. It's nice to not have to worry about creating single-method/single-attribute interfaces and dot them all over the place.
- ptx 7y agoGood point. But how can you know the types statically (at development-time) without defining interfaces?
- emodendroket 7y agoYou could specify that your method takes an object which has method XYZ accepting an int as its parameter and returning another int -- a kind of "anonymous" interface, I guess. Personally I don't like this kind of stuff because there's no guarantee that two objects with a convert method do the same thing when that method is called.