[Python-ideas] Adding "Typed" collections/iterators to Python
ethan at stoneleaf.us
Mon Dec 19 21:09:25 CET 2011
Nathan Rice wrote:
> On Mon, Dec 19, 2011 at 1:01 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>> Nathan Rice wrote:
>>> [[1, 2], [3, 4], [5, 6]] could serve as an alternate
>>> example of why you can't directly map child methods with the same
>> If you have to change the names, doesn't that negate the ability of "a
>> reliable method to make functions operate on both scalar and
>> vector values"?
> To clarify...
> Functions could reliably support both vector and scalar context, by
> checking that a type contract exists.
That sounds like type checking, which is not Pythonic. Duck-typing, on
the other hand, *is*.
some_obj = some_obj.capitalize()
--> capitalize_me("a simple string")
"A simple string"
--> capitalize_me(["a", "list", "of", "strings"])
["A", "List", "Of", "Strings"]
> Because of the name clash between parent and elementwise member
> methods when dealing with collections of collections (and some other
> classes), if the type contract provided "broadcast" versions of child
> methods, they would have to be provided with under an alias, perhaps X
> -> elementwise_X. I do not think people should be able to be
> oblivious of when they are calling collection and member methods, that
> encourages sloppy programming. I like the broadcast feature because
> it makes it easier to write code in a clear left to right narrative
> style, and that seems very pythonic to me compared with an
> "inside-out" style.
Duck-typing is neither oblivious, nor sloppy -- at least, not
inherently. Is my sample code above not what you had in mind?
More information about the Python-ideas