[Python-Dev] Python 3000 PEP: Postfix type declarations
Gustavo Carneiro
gjcarneiro at gmail.com
Sun Apr 1 14:47:39 CEST 2007
On 4/1/07, Gustavo Carneiro <gjcarneiro at gmail.com> wrote:
>
> On 4/1/07, Georg Brandl <g.brandl at gmx.net> wrote:
> [...]
>
> > Example
> > =======
> >
> > This is the standard ``os.path.normpath`` function, converted to type
> > declaration
> > syntax::
> >
> > def normpathƛ(path✎)✎:
> > """Normalize path, eliminating double slashes, etc."""
> > if path✎ == '':
> > return '.'
> > initial_slashes✓ = path✎.startswithƛ('/')✓
> > # POSIX allows one or two initial slashes, but treats three or
> > more
> > # as single slash.
> > if (initial_slashes✓ and
> > path✎.startswithƛ('//')✓ and not
> > path✎.startswithƛ('///')✓)✓:
> > initial_slashesℕ = 2
> > comps♨ = path✎.splitƛ('/')♨
> > new_comps♨ = []♨
> > for comp✎ in comps♨:
> > if comp✎ in ('', '.')⒯:
> > continue
> > if (comp✎ != '..' or (not initial_slashesℕ and not
> > new_comps♨)✓ or
> > (new_comps♨ and new_comps♨[-1]✎ == '..')✓)✓:
> > new_comps♨.appendƛ(comp✎)
> > elif new_comps♨:
> > new_comps♨.popƛ()✎
> > comps♨ = new_comps♨
> > path✎ = '/'.join(comps♨)✎
> > if initial_slashesℕ:
> > path✎ = '/'*initial_slashesℕ + path✎
> > return path✎ or '.'
> >
> > As you can clearly see, the type declarations add expressiveness, while
> > at the
> > same time they make the code look much more professional.
>
>
> Is this supposed to be a joke?
/me ashamed for not having noticed the date of this PEP... :P
--
Gustavo J. A. M. Carneiro
"The universe is always one step beyond logic."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20070401/52f10a0c/attachment.html
More information about the Python-Dev
mailing list