[PyKDE] a few issues

Gerard Vermeulen gerard.vermeulen at grenoble.cnrs.fr
Mon Aug 8 23:38:12 BST 2005


On Mon, 8 Aug 2005 21:07:43 +0100
Phil Thompson <phil at riverbankcomputing.co.uk> wrote:

> On Monday 08 August 2005 7:14 pm, Gerard Vermeulen wrote:
> > On Mon, 8 Aug 2005 18:50:27 +0100
> >
> > Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> > > On Friday 29 July 2005 6:16 am, Gerard Vermeulen wrote:
> > > > (1) (public) member data of class Foo does not show up in dir(Foo).
> > > >     This trips up tools like PyChecker and the standard library module
> > > >     inspect.py
> > >
> > > Works for me. Do you have an example .sip file in case I'm
> > > misunderstanding what you mean?
> >
> > Sorry, I was not clear enough: public data shows up in instances but not
> > in classes:
> >
> > %Module v 0
> >
> > class C
> > {
> > %TypeHeaderCode
> > class C
> > {
> > public:
> >     void alwaysVisible() {};
> >     int hiddenInClassButVisibleInInstance;
> > };
> > %End
> >
> > public:
> >     void alwaysVisible();
> >     int hiddenInClassButVisibleInInstance;
> > };
> >
> >
> > And now:
> >
> > [packer at titan data]$ python
> > Python 2.4 (#2, Feb 12 2005, 00:29:46)
> > [GCC 3.4.3 (Mandrakelinux 10.2 3.4.3-3mdk)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >
> > >>> from v import *
> > >>> dir(C)
> >
> > ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
> > '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__',
> > '__repr__', '__setattr__', '__str__', '__weakref__', 'alwaysVisible']
> >
> > >>> c = C()
> > >>> dir(c)
> >
> > ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
> > '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__',
> > '__repr__', '__setattr__', '__str__', '__weakref__', 'alwaysVisible',
> > 'hiddenInClassButVisibleInInstance']
> 
> But an instance variable doesn't make any sense in that context. What object 
> would you expect C.__dict__['hiddenInClassButVisibleInInstance'] to be?
>

Something similar as file.__dict__['softspace']:

>>> dir(file)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'close', 'closed', 'encoding', 'fileno', 'flush', 'isatty', 'mode', 'name', 'newlines', 'next', 'read', 'readinto', 'readline', 'readlines', 'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines', 'xreadlines']
>>> file.__dict__['seek']
<method 'seek' of 'file' objects>
>>> file.__dict__['softspace']
<member 'softspace' of 'file' objects>


I have attached a tar.gz with a slightly expanded version of class C which
makes the following example work: 

#!usr/bin/env python

from v import *

def main():
    c = C()
    c.hiddenInClassButVisibleInInstance = 1
    c.another.setValue(1)

if __name__ == '__main__':
    main()


But pychecker gives a false warning:

[packer at titan v-0.1]$ pychecker x.py
Processing x...

Warnings...

x.py:8: Object (c) has no attribute (another)
[packer at titan v-0.1]$

The funny thing is that pychecker accepts:
    c.hiddenInClassButVisibleInInstance = 1


Gerard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v-0.1.tar.gz
Type: application/octet-stream
Size: 1222 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20050809/5256615d/v-0.1.tar.obj


More information about the PyQt mailing list