[PyQt] BUG: sip instance attribute error: Re: [eric4] python qscintilla traceback with current snapshot also
Phil Thompson
phil at riverbankcomputing.com
Wed Feb 2 21:16:46 GMT 2011
On Wed, 2 Feb 2011 21:33:39 +0100, "Hans-Peter Jansen" <hpj at urpla.net>
wrote:
> [Oops, sorry, send too fast]
>
> Dear Phil,
>
> On Tuesday 01 February 2011, 22:26:43 Hans-Peter Jansen wrote:
>>
>> Phil, something is badly broken with the current release and the
>> snapshots.
>
> Here's the essence of the issue:
>
> class A(object):
> def __init__(self):
> # catch access a non existing attribute
> try:
> print self.a, type(self.a)
> except AttributeError:
> pass
>
> a = A()
>
> from PyQt4.Qsci import QsciScintilla
>
> # derive from a sip wrapped class
> class B(QsciScintilla):
> def __init__(self):
> # access a non existing attribute results in:
> # TypeError: 'sip.methoddescriptor' object is not callable
> try:
> print self.b, type(self.b)
> except AttributeError:
> pass
>
> b = B()
>
> results in:
>
> Traceback (most recent call last):
> File "sipinstance.py", line 22, in <module>
> b = B()
> File "sipinstance.py", line 18, in __init__
> print self.b, type(self.b)
> TypeError: 'sip.methoddescriptor' object is not callable
>
> Obviously, accessing non existing attributes in classes wrapped by sip
> causes havoc (an unexpected TypeError).
>
> At least for:
> python: 2.6
> sip: 4.12.1
> qt4: 4.6.3
> pyqt4: snapshot-4.8.4-278054fd857c
>
>
> I was able to fix eric with this diff:
>
> --- QScintilla/Editor.py~ 2011-02-02 21:31:20.741149390 +0100
> +++ QScintilla/Editor.py 2011-02-02 21:31:30.683988621 +0100
> @@ -1258,7 +1258,7 @@ class Editor(QsciScintillaCompat):
> """
> try:
>
self.supportedEols[self.getLineSeparator()].setChecked(True)
> - except AttributeError:
> + except (AttributeError, TypeError):
> pass
>
> def __eolChanged(self):
>
> Note: self.supportedEols doesn't exist, when this method is called the
> first
> time.
>
> Guess, it's sip 4.12.2 time ;-)
>
> Pete
If I run the code as above I get a "RuntimeError: underlying C/C++..." as
expected. Adding the missing call to QsciScintilla.__init__() (and creating
a QApplication at the start) then it runs fine (ie. an AttributeError is
raised).
Phil
More information about the PyQt
mailing list