[Python-checkins] CVS: python/nondist/peps pep-0232.txt,1.3,1.4

Barry Warsaw python-dev@python.org
Fri, 05 Jan 2001 23:03:14 -0800


Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv5506

Modified Files:
	pep-0232.txt 
Log Message:
Rewritten a bit for clarity, add a note about what you can set
func.__dict__ to, added a note in the open issues about support for
built-in function attributes, and included a link to the SF patch
#103123.


Index: pep-0232.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0232.txt,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** pep-0232.txt	2000/12/20 16:42:59	1.3
--- pep-0232.txt	2001/01/06 07:03:11	1.4
***************
*** 31,40 ****
      again, overloading docstrings with additional semantics.
  
!     For example, John Aycock[1] has written a system where docstrings
!     are used to define parsing rules.  Zope's ZPublisher ORB[2] uses
      docstrings to signal "publishable" methods, i.e. methods that can
!     be called through the web.  And Tim Peters[3] has developed a
!     system called doctest, where docstrings actually contain unit
!     tests.
  
      The problem with this approach is that the overloaded semantics
--- 31,39 ----
      again, overloading docstrings with additional semantics.
  
!     For example, John Aycock has written a system where docstrings are
!     used to define parsing rules[1].  Zope's ZPublisher ORB[2] uses
      docstrings to signal "publishable" methods, i.e. methods that can
!     be called through the web.  And Tim Peters has developed a system
!     called doctest[3], where docstrings actually contain unit tests.
  
      The problem with this approach is that the overloaded semantics
***************
*** 46,52 ****
  Proposal
  
!     This proposal simply adds a new dictionary to function objects,
!     called func_dict (a.k.a. __dict__).  This dictionary can be set
!     and get using ordinary attribute set and get syntax.
  
      Unbound methods also gain set and get attribute syntax, but they
--- 45,51 ----
  Proposal
  
!     This proposal adds a new dictionary to function objects, called
!     func_dict (a.k.a. __dict__).  This dictionary can be set and get
!     using ordinary attribute set and get syntax.
  
      Unbound methods also gain set and get attribute syntax, but they
***************
*** 58,62 ****
--- 57,65 ----
      the underlying function object.
  
+     A function object's __dict__ can also be set, but only to a
+     dictionary object (i.e. setting __dict__ to UserDict raises a
+     TypeError). 
  
+ 
  Examples
  
***************
*** 78,83 ****
  	    def a(self):
  	        'just a docstring'
  
- 	C.a.publish = 1
  	c = C()
  	if c.a.publish:
--- 81,86 ----
  	    def a(self):
  	        'just a docstring'
+             a.publish = 1
  
  	c = C()
  	if c.a.publish:
***************
*** 87,91 ****
  Other Uses
  
!     Paul Prescod enumerated a bunch of uses
  
      http://mail.python.org/pipermail/python-dev/2000-April/003364.html
--- 90,94 ----
  Other Uses
  
!     Paul Prescod enumerated a bunch of other uses:
  
      http://mail.python.org/pipermail/python-dev/2000-April/003364.html
***************
*** 96,104 ****
      1) Should function attributes be settable or gettable when in
         restricted execution mode?  What about __dict__/func_dict?
  
!     2) __doc__ is the only function attribute that currently has
         syntactic support for conveniently setting.  It may be
!        worthwhile to enhance the language for supporting easy function
!        attribute setting.  Here are some suggested syntaxes:
  
         def a {
--- 99,116 ----
      1) Should function attributes be settable or gettable when in
         restricted execution mode?  What about __dict__/func_dict?
+ 
+     2) Should built-in functions have writable attributes?  The
+        current patch only supports attributes on user defined
+        (i.e. Python) functions and methods.  Adding support to
+        built-in functions isn't difficult -- it would essentially
+        mirror the implementation for user defined functions (i.e. we
+        add a PyObject* to the PyCFunctionObject struct and write
+        getattro and setattro functions to read and write them).
  
!     3) __doc__ is the only function attribute that currently has
         syntactic support for conveniently setting.  It may be
!        worthwhile to eventually enhance the language for supporting
!        easy function attribute setting.  Here are some syntaxes
!        suggested by PEP reviewers:
  
         def a {
***************
*** 117,121 ****
  
         It isn't currently clear if special syntax is necessary or
!        desirable.
  
  
--- 129,134 ----
  
         It isn't currently clear if special syntax is necessary or
!        desirable.  It would be sufficient to postpone syntactic
!        support for some future PEP.
  
  
***************
*** 135,141 ****
      - useless until syntactic support is included
  
!     Countering some of these arguments is the observation that, with
!     the current implementation, __doc__ can in fact be set to any type
!     of object, so some semblance of writable function attributes are
      already feasible.  But that approach is yet another corruption of
      __doc__.
--- 148,154 ----
      - useless until syntactic support is included
  
!     Countering some of these arguments is the observation that with
!     vanilla Python 2.0, __doc__ can in fact be set to any type of
!     object, so some semblance of writable function attributes are
      already feasible.  But that approach is yet another corruption of
      __doc__.
***************
*** 153,158 ****
  
  Reference Implementation
  
!     A reference implementation will be uploaded to SourceForge soon.
  
  
--- 166,176 ----
  
  Reference Implementation
+ 
+     The reference implementation is available on SourceForge as a
+     patch against the Python CVS tree (patch #103123).  This patch
+     doesn't include the regrtest module and output file.  Those are
+     available upon request.
  
!     http://sourceforge.net/patch/?func=detailpatch&patch_id=103123&group_id=5470