[Python-Dev] Python 3000 PEP: Postfix type declarations (original) (raw)
Gustavo Carneiro gjcarneiro at gmail.com
Sun Apr 1 14:41:56 CEST 2007
- Previous message: [Python-Dev] Python 3000 PEP: Postfix type declarations
- Next message: [Python-Dev] Python 3000 PEP: Postfix type declarations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 '.' initialslashes✓ = path✎.startswithƛ('/')✓ # POSIX allows one or two initial slashes, but treats three or more # as single slash. if (initialslashes✓ and path✎.startswithƛ('//')✓ and not path✎.startswithƛ('///')✓)✓: initialslashesℕ = 2 comps♨ = path✎.splitƛ('/')♨ newcomps♨ = []♨ for comp✎ in comps♨: if comp✎ in ('', '.')⒯: continue if (comp✎ != '..' or (not initialslashesℕ and not newcomps♨)✓ or (newcomps♨ and newcomps♨[-1]✎ == '..')✓)✓: newcomps♨.appendƛ(comp✎) elif newcomps♨: newcomps♨.popƛ()✎ comps♨ = newcomps♨ path✎ = '/'.join(comps♨)✎ if initialslashesℕ: path✎ = '/'*initialslashesℕ + 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? Please tell me this isn't a real PEP. While I'm all for allowing unicode identifiers in Python, postfix type annotations make Python look like Perl. And how can you claim this code is more readable? It certainly is less readable, not more.
I agree that Python should support type annotations, but they should be optional and only present at the function interfaces, i.e. specify the type in the function parameter lists, like in plain old C.
+1 from me for allowing unicode identifiers.
-MAXVOTE for type annotations in identifiers.
-- 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/e35ebbfb/attachment.html
- Previous message: [Python-Dev] Python 3000 PEP: Postfix type declarations
- Next message: [Python-Dev] Python 3000 PEP: Postfix type declarations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]