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

Guido van Rossum gvanrossum@users.sourceforge.net
2001年4月23日 09:35:35 -0700


Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv25620
Modified Files:
	pep-0252.txt 
Log Message:
Check in a little more about attribute descriptors. More to follow
later today.
Index: pep-0252.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0252.txt,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** pep-0252.txt	2001年04月20日 13:46:17	1.3
--- pep-0252.txt	2001年04月23日 16:35:33	1.4
***************
*** 21,28 ****
 using attribute descriptors, or descriptors for short.
 Descriptors unify and generalize several different common
! mechanisms used for describing attributes: a descriptor can be an
! unbound method, a typed field in the object structure, or a
! generalized attribute represented by getter and setter functions
! (or just a getter function, for read-only attributes).
 
 Introduction
--- 21,27 ----
 using attribute descriptors, or descriptors for short.
 Descriptors unify and generalize several different common
! mechanisms used for describing attributes: a descriptor can
! describe a method, a typed field in the object structure, or a
! generalized attribute represented by getter and setter functions.
 
 Introduction
***************
*** 52,64 ****
 
 The class-based introspection API is used primarily for class
! instances; it is also used by Digital Creations's
! ExtensionClasses. It assumes that all data attributes of an
! object x are stored in the dictionary x.__dict__, and that all
! methods and class variables can be found by inspection of x's
! class, written as x.__class__. Classes have a __dict__ attribute,
! which yields a dictionary containing methods and class variables
! defined by the class itself, and a __bases__ attribute, which is a
! tuple of base classes that must be inspected recursively. Some
! assumption here are:
 
 - attributes defined in the instance dict override attributes
--- 51,63 ----
 
 The class-based introspection API is used primarily for class
! instances; it is also used by Jim Fulton's ExtensionClasses. It
! assumes that all data attributes of an object x are stored in the
! dictionary x.__dict__, and that all methods and class variables
! can be found by inspection of x's class, written as x.__class__.
! Classes have a __dict__ attribute, which yields a dictionary
! containing methods and class variables defined by the class
! itself, and a __bases__ attribute, which is a tuple of base
! classes that must be inspected recursively. Some assumption here
! are:
 
 - attributes defined in the instance dict override attributes
***************
*** 101,108 ****
 attribute names __methods__ and __members__, respectively.
 
! Digital Creations's ExtensionClasses ignore the type API, and
! instead emulate the class API, which is more powerful. In this
! PEP, I propose to phase out the type API in favor of supporting
! the class API for all types.
 
 One argument in favor of the class API is that it doesn't require
--- 100,107 ----
 attribute names __methods__ and __members__, respectively.
 
! Jim Fulton's ExtensionClasses ignore the type API, and instead
! emulate the class API, which is more powerful. In this PEP, I
! propose to phase out the type API in favor of supporting the class
! API for all types.
 
 One argument in favor of the class API is that it doesn't require
***************
*** 239,243 ****
 6. Attribute descriptors
 
! XXX
 
 The introspection API is a read-only API. We don't define the
--- 238,267 ----
 6. Attribute descriptors
 
! This is where it gets interesting -- and messy. Attribute
! descriptors (descriptors for short) are stored in the
! meta-object's __dict__, and have two uses: a descriptor can be
! used to get or set the corresponding attribute value on the
! (non-meta) object, and it has an additional interface that
! describes the attribute for documentation or introspection
! purposes.
! 
! There is little prior art in Python for designing the
! descriptor's interface, neither for getting/setting the value
! nor for describing the attribute otherwise, except some trivial
! properties (e.g. it's reasonable to assume that __name__ and
! __doc__ should be the attribute's name and docstring). I will
! propose such an API below.
! 
! If an object found in the meta-object's __dict__ is not an
! attribute descriptor, backward compatibility dictates
! semantics. This basically means that if it is a Python
! function or an unbound method, the attribute is a method;
! otherwise, it is the default value for a data attribute.
! Backwards compatibility also dictates that (in the absence of a
! __setattr__ method) it is legal to assign to an attribute of
! type method, and that this creates a data attribute shadowing
! the method for this particular instance. However, these
! semantics are only required for backwards compatibility with
! regular classes.
 
 The introspection API is a read-only API. We don't define the
***************
*** 249,252 ****
--- 273,280 ----
 currently instances support assignment to __class__ and __dict__,
 and classes support assignment to __bases__ and __dict__.)
+ 
+ Specification of the attribute descriptor API
+ 
+ XXX
 
 Discussion

AltStyle によって変換されたページ (->オリジナル) /