Noticed Hans Nowak's observations on an area where Python's dynamic typing falls short in regards to refactoring. Read it; thought "yeah, ok. good point." and moved on.
Fast forward and zoom to my world. I'm working on a Python web app (in webware, btw) that has an object which contains a tuple. This tuple is populated by a bunch of integers that are retrieved from a database table. So far, so good.
Well, I have a case where I need to pass an integer from a webpage and determine if that integer is in the aforementioned tuple - seems straightforward. Pass the integer via webware's request object and check the tuple to see if the integer there using this fairly common method -
if integer is in tuple:
return True
else:
return False
Nothing unusual there. Worked in the past in other cases fine. But what happens in this case? It returns False, every stinking time - even when the passed integer is a known member. Ok, so I'm officially befuddled.
So, I start digging through things and discover that the integer passed from the page is a StringType and the integers in the tuple are all LongType. Ok, not really a surprise. But, why won't Python convert the types and make the comparison? That's supposed to be the benefit of using a dynamically typed language.
In strongly typed languages, you can manually coerce one data type to another. Python supports this too - at least for now. But it doesn't seem right to have to resort to doing something manually that the language is supposed to do for you automatically.
Maybe this all makes sense to others and there's something going on here that I just don't completely understand. There are certainly gaps in my knowledge of Python. But this issue just caught me off guard because it was completely unexpected.