Showing content from http://mail.python.org/pipermail/python-dev/attachments/20070401/52f10a0c/attachment.html below:
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."
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4