python/nondist/peps pep-0318.txt,1.7,1.8

Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27770 Modified Files: pep-0318.txt Log Message: fixed list containment (indents) & whitespace Index: pep-0318.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0318.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** pep-0318.txt 30 Mar 2004 03:48:59 -0000 1.7 --- pep-0318.txt 30 Mar 2004 13:39:21 -0000 1.8 *************** *** 3,7 **** Version: $Revision$ Last-Modified: $Date$ ! Author: Kevin D. Smith <Kevin.Smith@theMorgue.org>, Jim Jewett <jimjjewett@users.sourceforge.net>, Skip Montanaro <skip@pobox.com> --- 3,7 ---- Version: $Revision$ Last-Modified: $Date$ ! Author: Kevin D. Smith <Kevin.Smith@theMorgue.org>, Jim Jewett <jimjjewett@users.sourceforge.net>, Skip Montanaro <skip@pobox.com> *************** *** 62,65 **** --- 62,66 ---- modifications to classes. + Background ========== *************** *** 74,86 **** ``comp.lang.python`` by `Gareth McCaughan`_. ! .. _syntactic support for decorators: http://www.python.org/doc/essays/ppt/python10/py10keynote.pdf ! .. _10th python conference: http://www.python.org/workshops/2002-02/ ! .. _michael hudson raised the topic: http://mail.python.org/pipermail/python-dev/2002-February/020005.html ! .. _he later said: http://mail.python.org/pipermail/python-dev/2002-February/020017.html ! .. _gareth mccaughan: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=slrna40k88.2h9o.Gareth.McCaughan%40g.local Class decorations seem like an obvious next step because class definition and function definition are syntactically similar. Design Goals ============ --- 75,93 ---- ``comp.lang.python`` by `Gareth McCaughan`_. ! .. _syntactic support for decorators: ! http://www.python.org/doc/essays/ppt/python10/py10keynote.pdf ! .. _10th python conference: ! http://www.python.org/workshops/2002-02/ ! .. _michael hudson raised the topic: ! http://mail.python.org/pipermail/python-dev/2002-February/020005.html ! .. _he later said: ! http://mail.python.org/pipermail/python-dev/2002-February/020017.html ! .. _gareth mccaughan: ! http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=slrna40k88.2h9o.Gareth.McCaughan%40g.local Class decorations seem like an obvious next step because class definition and function definition are syntactically similar. + Design Goals ============ *************** *** 110,114 **** there`_" ! .. _toy parser tools out there: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=mailman.1010809396.32158.python-list%40python.org Proposed Syntax --- 117,123 ---- there`_" ! .. _toy parser tools out there: ! http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=mailman.1010809396.32158.python-list%40python.org ! Proposed Syntax *************** *** 129,132 **** --- 138,142 ---- pass + Alternate Proposals =================== *************** *** 142,146 **** `alternatives to "as"`_ have been proposed. :-) ! .. _alternatives to "as": http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=mailman.236.1079968472.742.python-list%40python.org&rnum=2&prev=/groups%3Fq%3Dpython%2Bpep%2B318%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3Dmailman.236.1079968472.742.python-list%2540python.org%26rnum%3D2 :: --- 152,157 ---- `alternatives to "as"`_ have been proposed. :-) ! .. _alternatives to "as": ! http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=mailman.236.1079968472.742.python-list%40python.org&rnum=2&prev=/groups%3Fq%3Dpython%2Bpep%2B318%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3Dmailman.236.1079968472.742.python-list%2540python.org%26rnum%3D2 :: *************** *** 162,166 **** function name. ! .. _Python Template Language: http://www.mems-exchange.org/software/quixote/doc/PTL.html :: --- 173,178 ---- function name. ! .. _Python Template Language: ! http://www.mems-exchange.org/software/quixote/doc/PTL.html :: *************** *** 180,183 **** --- 192,196 ---- it would require the introduction of a new keyword. + Current Implementation ====================== *************** *** 200,203 **** --- 213,217 ---- .. _patch: http://starship.python.net/crew/mwh/hacks/meth-syntax-sugar-3.diff + Examples ======== *************** *** 212,224 **** isn't actually "wrapped" in the usual sense. ! :: ! def onexit(f): ! import atexit ! atexit.register(f) ! return f ! def func() [onexit]: ! ... 2. Define a class with a singleton instance. Note that once the class --- 226,238 ---- isn't actually "wrapped" in the usual sense. ! :: ! def onexit(f): ! import atexit ! atexit.register(f) ! return f ! def func() [onexit]: ! ... 2. Define a class with a singleton instance. Note that once the class *************** *** 226,281 **** to create more instances. (From Shane Hathaway on ``python-dev``.) ! :: ! def singleton(cls): ! return cls() ! class MyClass [singleton]: ! ... 3. Decorate a function with release information. (Based on an example posted by Anders Munch on ``python-dev``.) ! :: ! def release(**kwds): ! def decorate(f): ! for k in kwds: ! setattr(f, k, kwds[k]) ! return f ! return decorate ! def mymethod(f) [release(versionadded="2.2", ! author="Guido van Rossum")]: ! ... 4. Enforce function argument and return types. ! :: ! def accepts(*types): ! def check_accepts(f): ! assert len(types) == f.func_code.co_argcount ! def new_f(*args, **kwds): ! for (a, t) in zip(args, types): ! assert isinstance(a, t), \ ! "arg %r does not match %s" % (a,t) ! return f(*args, **kwds) ! return new_f ! return check_accepts ! def returns(rtype): ! def check_returns(f): ! def new_f(*args, **kwds): ! result = f(*args, **kwds) ! assert isinstance(result, rtype), \ ! "return value %r does not match %s" % (result,rtype) ! return result ! return new_f ! return check_returns ! def func(arg1, arg2) [accepts(int, (int,float)), ! returns((int,float))]: ! return arg1 * arg2 5. Declare that a class implements a particular (set of) interface(s). --- 240,295 ---- to create more instances. (From Shane Hathaway on ``python-dev``.) ! :: ! def singleton(cls): ! return cls() ! class MyClass [singleton]: ! ... 3. Decorate a function with release information. (Based on an example posted by Anders Munch on ``python-dev``.) ! :: ! def release(**kwds): ! def decorate(f): ! for k in kwds: ! setattr(f, k, kwds[k]) ! return f ! return decorate ! def mymethod(f) [release(versionadded="2.2", ! author="Guido van Rossum")]: ! ... 4. Enforce function argument and return types. ! :: ! def accepts(*types): ! def check_accepts(f): ! assert len(types) == f.func_code.co_argcount ! def new_f(*args, **kwds): ! for (a, t) in zip(args, types): ! assert isinstance(a, t), \ ! "arg %r does not match %s" % (a,t) ! return f(*args, **kwds) ! return new_f ! return check_accepts ! def returns(rtype): ! def check_returns(f): ! def new_f(*args, **kwds): ! result = f(*args, **kwds) ! assert isinstance(result, rtype), \ ! "return value %r does not match %s" % (result,rtype) ! return result ! return new_f ! return check_returns ! def func(arg1, arg2) [accepts(int, (int,float)), ! returns((int,float))]: ! return arg1 * arg2 5. Declare that a class implements a particular (set of) interface(s). *************** *** 283,310 **** experience with `PyProtocols`_. ! .. _PyProtocols: http://peak.telecommunity.com/PyProtocols.html ! :: ! def provides(*interfaces): ! """ ! An actual, working, implementation of provides for ! the current implementation of PyProtocols. Not ! particularly important for the PEP text. ! """ ! def provides(typ): ! declareImplementation(typ, instancesProvide=interfaces) ! return typ ! return provides ! class IBar(Interface): ! """Declare something about IBar here""" ! class Foo(object) [provides(IBar)]: ! """Implement something here...""" Of course, all these examples are possible today, though without the syntactic support. Open Issues =========== --- 297,325 ---- experience with `PyProtocols`_. ! .. _PyProtocols: http://peak.telecommunity.com/PyProtocols.html ! :: ! def provides(*interfaces): ! """ ! An actual, working, implementation of provides for ! the current implementation of PyProtocols. Not ! particularly important for the PEP text. ! """ ! def provides(typ): ! declareImplementation(typ, instancesProvide=interfaces) ! return typ ! return provides ! class IBar(Interface): ! """Declare something about IBar here""" ! class Foo(object) [provides(IBar)]: ! """Implement something here...""" Of course, all these examples are possible today, though without the syntactic support. + Open Issues =========== *************** *** 316,320 **** ``python-dev``. ! .. _strong arguments: http://mail.python.org/pipermail/python-dev/2004-March/thread.html --- 331,336 ---- ``python-dev``. ! .. _strong arguments: ! http://mail.python.org/pipermail/python-dev/2004-March/thread.html
participants (1)
-
goodger@users.sourceforge.net