Article mentions a type `List[Union[TemperatureMeasurement, HumidityMeasurement]]` to average over, so a list of potentially mixed temp and humidity. Which I guess you could average but has no physical meaning (though not the point of the article).
I think what is meant is Union[List[TemperatureMeasurement], List[HumidityMeasurement]], , so a list of either just TemperatureMeasurements or a list of only HumidityMeasurements.
> you care only about the behaviour ... not the explicit type of that input
"duck typing" is a run-time equivalent of structural typing. It would be a little more accurate to say the value's properties (ie., the object behaviour) *is* the type.
A "protocol" isnt a means of "ignoring the real type, ie., the name we give a type". It is a means of expressing a structural type. Nominal typing, ie., a type "being some name" isn't fundamental.
Indeed, my biggest complaint with python's static typing efforts are how hamfisted nominal typing has been shoved on top of python, as-if it were just "failing to be java".
> Indeed, my biggest complaint with python's static typing efforts are how hamfisted nominal typing has been shoved on top of python, as-if it were just "failing to be java".
This is the best way I've seen my feelings on this summarized. Thanks! I really find that efforts to bring nominal typing to Python really just restrict it, and it becomes not the same language anymore. If I want that kind of typing, I prefer to use a language that does it properly. Otherwise, I want a type system that works for how Python is designed.
I'm really finding these days that I have to restrict the range of types my functions are designed to work on just to satisfy a bunch of linters. It's very annoying. And imho goes against the grain of why I chose Python in the first place.
I regard, `Callable[Blah..., ...., ..., [Blah, Blah....]]` essentially a hostile gesture to the data profession.
Guido wanted to create a procedural imperative language that used runtime tricks to look simple. What he actually created was a highly (ad-hoc) polymorphic language with extraordinary power.
This is the inverse story to javascript: there brendan wanted to hide the lisp. Here, guido accidentally created one.
Since realising this guido has gone about doing everything to hobble efforts to realise the underlying efficacy of the python model -- and shove it back into the procedural box he had intended it to be in.
Given python3, this appears to be a remarkable contradiction. Python2 was what guido wanted, when python3 came along and "software engineers" won over "educators", playing the "lets keep it dumb and procedural" game was conclusively dead.
I have a lot of respect for Guido's vision, but this approach to typing has frustrated me. It feels like he's fighting a proxy-war on procedural-python, using the type system to force the rest of us to concede.
What exactly is wrong with Callable though? The argument and return types can be structural types. It doesn’t really make the function less powerful if you only constrain the input to have the exact interface you need, and nothing more.
I think what is meant is Union[List[TemperatureMeasurement], List[HumidityMeasurement]], , so a list of either just TemperatureMeasurements or a list of only HumidityMeasurements.