[Patches] [ python-Patches-477330 ] add __slot_docs__ and __slot_types__

noreply@sourceforge.net noreply@sourceforge.net
Tue, 04 Dec 2001 11:14:29 -0800


Patches item #477330, was opened at 2001-11-01 15:08
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=477330&group_id=5470

Category: Core (C code)
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Michael McLay (mclay)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: add __slot_docs__ and __slot_types__

Initial Comment:
The slot members defined using__slots__  cannot be
assigned doc strings in the current implementation. 
This patch adds the ability to attach doc strings to a
slot member by assigning a dictionary to the
__slot_docs__ class variable.

>>> class B(object):
    __slots__ = ['a','b','c']
    __slot_docs__ = {'a':"the a docstring",'b':"the b
doc string"}
    __slot_types__ = {'a':(int,str), 'c':int, }

>>> B.a.__doc__
'the a docstring'
>>> 

The __slot_types__ class variable adds an optional type
constraint for the slot.  If a dictionary with a type
or list of types is associated with a member name then
the isinstance() method will be called on that member
when the get and set methods for the member are called.

>>> class B(object):
    __slots__ = ['a','b','c']
    __slot_docs__ = {'a':"the a docstring",'b':"the b
doc string"}
    __slot_types__ = {'a':(int,str), 'c':int, }
    def __getattribute__(self,name):
	    print "help please", name
	    return object.__getattribute__(self, name)

	
>>> class B(object):
    __slots__ = ['a','b','c']
    __slot_docs__ = {'a':"the a docstring",'b':"the b
doc string"}
    __slot_types__ = {'a':(int,str), 'c':int, }

>>> b = B()
>>> b.a
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in ?
    b.a
TypeError: The value of B.a is of type <type
'NoneType'>. This is not one of the defined slot_types
>>> b.a = 4
>>> b.a
4
>>> b.a = 34.3
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in ?
    b.a = 34.3
TypeError: The type of <type 'float'> is not one of the
defined slot_types for B.a
>>> b.b
>>> b.b = 3
>>> b.b = 34.2
>>> b.b
34.200000000000003
>>> b.a = "fish"
>>> b.a
'fish'
>>> 

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-04 11:14

Message:
Logged In: YES 
user_id=6380

Rejecting, for the same reason why I rejected the addmember
patch.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-11-02 21:14

Message:
Logged In: YES 
user_id=31435

In Guido's absence (he's on leave the rest of November), 
I'm Postponing this.  Feature cutoff for 2.2 has already 
occurred, and we've got all we can do (esp. in Guido's 
absence!) to finish what's already there.  I don't even 
have time to mention <wink> that a patch without doc and 
test case changes is dead on arrival, let alone time to 
think about it.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2001-11-02 16:13

Message:
Logged In: YES 
user_id=21627

-1. I think there should be proper syntax for slots, which 
should include support for doc strings. The "optional 
static typing" part should be coordinated with PEP 245.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=477330&group_id=5470