On 4/1/07, <b class="gmail_sendername">Gustavo Carneiro</b> <<a href="mailto:gjcarneiro@gmail.com">gjcarneiro@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 4/1/07, <b class="gmail_sendername">Georg Brandl</b> <<a href="mailto:g.brandl@gmx.net" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">g.brandl@gmx.net</a>> wrote:<br>[...]<div><span class="q" id="q_111ad2a8290fb7e9_1">
<br><div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Example<br>=======<br><br>This is the standard ``os.path.normpath`` function, converted to type declaration<br>syntax::<br><br> def normpathƛ(path✎)✎:<br> """Normalize path, eliminating double slashes, etc."""
<br> if path✎ == '':<br> return '.'<br> initial_slashes✓ = path✎.startswithƛ('/')✓<br> # POSIX allows one or two initial slashes, but treats three or more<br> # as single slash.
<br> if (initial_slashes✓ and<br> path✎.startswithƛ('//')✓ and not path✎.startswithƛ('///')✓)✓:<br> initial_slashesℕ = 2<br> comps♨ = path✎.splitƛ('/')♨<br>
new_comps♨ = []♨
<br> for comp✎ in comps♨:<br> if comp✎ in ('', '.')⒯:<br> continue<br> if (comp✎ != '..' or (not initial_slashesℕ and not new_comps♨)✓ or<br> (new_comps♨ and new_comps♨[-1]✎ == '..')✓)✓:
<br> new_comps♨.appendƛ(comp✎)<br> elif new_comps♨:<br> new_comps♨.popƛ()✎<br> comps♨ = new_comps♨<br> path✎ = '/'.join(comps♨)✎<br> if initial_slashesℕ:
<br> path✎ = '/'*initial_slashesℕ + path✎<br> return path✎ or '.'<br><br>As you can clearly see, the type declarations add expressiveness, while at the<br>same time they make the code look much more professional.
</blockquote><div><br></div></div></span></div> Is this supposed to be a joke?</blockquote><div><br> /me ashamed for not having noticed the date of this PEP... :P<br></div></div><br>-- <br>Gustavo J. A. M. Carneiro<br>
"The universe is always one step beyond logic."