[Python-ideas] [Python-3000] PEP 3107 Function Annotations: overloadable ->
Josiah Carlson
jcarlson at uci.edu
Tue Jan 2 19:29:06 CET 2007
Tony Lownds <tony at pagedna.com> wrote:
> On Jan 1, 2007, at 10:34 PM, Josiah Carlson wrote:
> > -1 on the -> operator as specified in the email you link. There is no
> > reason to add aribtrary operators for call-site annotations.
>
> What was the arbitrary operator? -> is not arbitrary, and there was a
> reason given to add it.
I misunderstood portions of the post.
> > PEP 3107
> > has already defined the syntax for function definition site
> > annotations
> > as follows...
> >
> > def name(argument=default:annotation) -> annotation:
> > body
>
> You mean
>
> def name(argument:annotation=default)
Thank you for the correction. Maybe I'm the only one, but I would
prefer the default value to come before the annotation.
> > The mail you link, talks about an arbitrary -> operator for call-site
> > annotations. Without seeing actual use-cases where a -> operator
> > would
> > be useful in the real-world, I can't help but be -1 on the -> operator
> > and -1 on the __returns__ method.
>
> That email had a use case... The gain is being able to write
>
> def wrap(text: str, split: Function(str)-> list):
>
> instead of
>
> def wrap(text: str, split: Function(str) == list):
>
> or
>
> def wrap(text: str, split: Function(str, returns=list)):
>
> or one of the other methods that Kay came up with.
Kay's mail specified:
maptype = Function( Function(object)->object, list) -> list
That looks to me like the -> operator being used anywhere the user
desires.
With your examples above, I see the use-case, but I'm still -1 (for the
same reasons).
For other reasons to be -1 on ->, we can look at how it would be abused
to violate the one obvious way to do things...
Stack() -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
t = Tree()
t -> (t -> (1,2), t -> (3,4))
Or for a concrete example...
class mylist(list):
def __returns__(self, arg):
self.append(arg)
return self
mylist() -> 1 -> 2 -> 3 -> 4 -> 5
Right now those things aren't done because the punctuation for doing it
isn't as natural as -> would be.
- Josiah
More information about the Python-ideas
mailing list