There is general agreement that syntactic support is desirable to Readers are pointed to the ternary operatorĭiscussions that were associated with PEP 308 for another example of Syntax discussions in general appear to cause more contention thanĪlmost anything else.Strong preexisting meme that captures the concept. Very few people will have had any experience with theĭecorator concept before encountering it in Python. Used at least one other programming language, much of Python is Passing acquaintance with algebra (or even basic arithmetic) or have Overall unfamiliarity with the concept.You’re doing.” The best that seems possible is to keep new users fromĬreating a wildly incorrect mental model of what the syntax means. That people new to the concept will think, “Oh yeah, I know what There’s no obvious way to structure this information so “messing things up” (both visually and with regards to the language With fairly strong constraints on what can and can’t be done without Python is a syntactically simple language Beyond that there seems to be noĬlear consensus where to place this information. Disagreement about where the “declaration of intent” belongs.Īlmost everyone agrees that decorating/transforming a function at theĮnd of its definition is suboptimal.There is no one clear reason why this should be so, but a few problems Python-dev mailing list about how best to implement function decorators. Have raged off-and-on at times in both and the Wonder why it’s been so difficult to arrive at a consensus. It’s been assumed sinceĪpproximately that time that some syntactic support for them wouldĮventually be added to the language. Two decorators ( classmethod() and staticmethod()) have beenĪvailable in Python since version 2.2. PEP 3129 proposes to add class decorators as of Python 2.6. Python 2.4, only function/method decorators are being added. To having an easier way to make simple modifications to classes. Using metaclasses is sufficiently obscure that there is some attraction Almost certainly, anything which couldīe done with class decorators could be done using metaclasses, but Modifying classes in this fashion is also possible, though the benefitsĪre not as immediately apparent. The definition of the rest of the function’s external interface. For largeįunctions this separates a key component of the function’s behavior from Places the actual transformation after the function body. The current method of applying a transformation to a function or method This PEP introduces new syntax for transformations of aįunction or method declaration. Should be made at the same point in the code where the declaration The current method for transforming functions and methods (for instance,ĭeclaring them as a class or static method) is awkward and can lead toĬode that is difficult to understand. Nor is it an attempt to exhaustively list all the positives and It does notĪttempt to cover the huge number of potential alternative syntaxes, Process that resulted in the decisions that were made. This document is meant to describe the decorator syntax and the Jewett, Skip Montanaro, Anthony Baxter Status : Final Type : Standards Track Created : 0 Python-Version : 2.4 Post-History : 0, 1, 2, 2, 3, Toggle light / dark / auto colour theme PEP 318 – Decorators for Functions and Methods Author : Kevin D. PEP 318 – Decorators for Functions and Methods | Following system colour scheme Selected dark colour scheme Selected light colour scheme Python Enhancement Proposals
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |