Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Python gdb.Function is an old-style class?
@ 2016-07-21 17:22 Paul Smith
  2016-07-21 17:38 ` Paul_Koning
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Smith @ 2016-07-21 17:22 UTC (permalink / raw)
  To: gdb

Hi all; I am writing some Python functions that subclass from
gdb.Function, and I use super() to call the superclass __init__()

It works, but pylint is failing with an error "Use of super on an old
style class".  This is usually shown when a Python2 class does not
inherit, ultimately, from the object.

Is there something magic that needs to happen to make gdb.Function
recognized as a new-style class?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Python gdb.Function is an old-style class?
  2016-07-21 17:22 Python gdb.Function is an old-style class? Paul Smith
@ 2016-07-21 17:38 ` Paul_Koning
  2016-07-21 18:06   ` Paul_Koning
  2016-07-21 18:37   ` Paul Smith
  0 siblings, 2 replies; 9+ messages in thread
From: Paul_Koning @ 2016-07-21 17:38 UTC (permalink / raw)
  To: psmith; +Cc: gdb


> On Jul 21, 2016, at 1:22 PM, Paul Smith <psmith@gnu.org> wrote:
> 
> Hi all; I am writing some Python functions that subclass from
> gdb.Function, and I use super() to call the superclass __init__()
> 
> It works, but pylint is failing with an error "Use of super on an old
> style class".  This is usually shown when a Python2 class does not
> inherit, ultimately, from the object.
> 
> Is there something magic that needs to happen to make gdb.Function
> recognized as a new-style class?

You could just call gdb.Function.__init__(self) explicitly rather than the syntactic sugar of super().  But does subclassing work at all?  I had the impression that many gdb classes don't allow subclassing.  Or it might not be rejected but it may not work.  I haven't looked at how to make a class in C that can be subclassed; my impression is that it definitely takes work and I don't know if the necessary magic has been implemented.

For example, method calls in subclassable classes have to be via attribute lookups and Python calls, they can't be direct calls.  Ditto data attribute references.

	paul


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Python gdb.Function is an old-style class?
  2016-07-21 17:38 ` Paul_Koning
@ 2016-07-21 18:06   ` Paul_Koning
  2016-07-21 18:37   ` Paul Smith
  1 sibling, 0 replies; 9+ messages in thread
From: Paul_Koning @ 2016-07-21 18:06 UTC (permalink / raw)
  To: psmith; +Cc: gdb


> On Jul 21, 2016, at 1:38 PM, Paul Koning <Paul_Koning@dell.com> wrote:
> 
> 
>> On Jul 21, 2016, at 1:22 PM, Paul Smith <psmith@gnu.org> wrote:
>> 
>> Hi all; I am writing some Python functions that subclass from
>> gdb.Function, and I use super() to call the superclass __init__()
>> 
>> It works, but pylint is failing with an error "Use of super on an old
>> style class".  This is usually shown when a Python2 class does not
>> inherit, ultimately, from the object.
>> 
>> Is there something magic that needs to happen to make gdb.Function
>> recognized as a new-style class?
> 
> You could just call gdb.Function.__init__(self) explicitly rather than the syntactic sugar of super(). 

I just tried the example shown in the manual, and it runs without errors.  I don't get the error message you quoted, and the resulting function works correctly.

So disregard my previous comment about subclassing.  Sorry about the confusion.

	paul


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Python gdb.Function is an old-style class?
  2016-07-21 17:38 ` Paul_Koning
  2016-07-21 18:06   ` Paul_Koning
@ 2016-07-21 18:37   ` Paul Smith
  2016-07-21 18:50     ` Phil Muldoon
  1 sibling, 1 reply; 9+ messages in thread
From: Paul Smith @ 2016-07-21 18:37 UTC (permalink / raw)
  To: Paul_Koning; +Cc: gdb

On Thu, 2016-07-21 at 17:38 +0000, Paul_Koning@Dell.com wrote:
> > 
> > On Jul 21, 2016, at 1:22 PM, Paul Smith <psmith@gnu.org> wrote:
> > 
> > Hi all; I am writing some Python functions that subclass from
> > gdb.Function, and I use super() to call the superclass __init__()
> > 
> > It works, but pylint is failing with an error "Use of super on an old
> > style class".  This is usually shown when a Python2 class does not
> > inherit, ultimately, from the object.
> > 
> > Is there something magic that needs to happen to make gdb.Function
> > recognized as a new-style class?
> You could just call gdb.Function.__init__(self) explicitly rather
> than the syntactic sugar of super().

Well, super() is not always just syntactic sugar.  It actually makes a
big difference in some class hierarchies (it solves the diamond
inheritance problem for example).  And, it avoids needing to modify
subclasses if you change the superclass hierarchy which is nice.

However, in my specific situation they are equivalent and that's
definitely the approach I'll take, if there's no other straightforward
solution.

> I just tried the example shown in the manual, and it runs without
> errors.  I don't get the error message you quoted, and the resulting
> function works correctly.

Sorry I was unclear.  The warning isn't generated by Python, and indeed
using super() appears to work fine in my code as well.

However part of our static analysis requires that all Python code added
to the codebase, including local GDB functions, pass Pylint.  It's
pylint which is complaining about this, not Python itself.

I suppose it could be a Pylint problem...?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Python gdb.Function is an old-style class?
  2016-07-21 18:37   ` Paul Smith
@ 2016-07-21 18:50     ` Phil Muldoon
  2016-07-21 19:13       ` Paul_Koning
  2016-07-21 19:17       ` Paul Smith
  0 siblings, 2 replies; 9+ messages in thread
From: Phil Muldoon @ 2016-07-21 18:50 UTC (permalink / raw)
  To: psmith, Paul_Koning; +Cc: gdb

On 21/07/16 19:37, Paul Smith wrote:
> On Thu, 2016-07-21 at 17:38 +0000, Paul_Koning@Dell.com wrote:
>>>
>>> On Jul 21, 2016, at 1:22 PM, Paul Smith <psmith@gnu.org> wrote:
>>>
>>> Hi all; I am writing some Python functions that subclass from
>>> gdb.Function, and I use super() to call the superclass __init__()
>>>
>>> It works, but pylint is failing with an error "Use of super on an old
>>> style class".  This is usually shown when a Python2 class does not
>>> inherit, ultimately, from the object.
>>>
>>> Is there something magic that needs to happen to make gdb.Function
>>> recognized as a new-style class?
>> You could just call gdb.Function.__init__(self) explicitly rather
>> than the syntactic sugar of super().
> 
> Well, super() is not always just syntactic sugar.  It actually makes a
> big difference in some class hierarchies (it solves the diamond
> inheritance problem for example).  And, it avoids needing to modify
> subclasses if you change the superclass hierarchy which is nice.

> However part of our static analysis requires that all Python code added
> to the codebase, including local GDB functions, pass Pylint.  It's
> pylint which is complaining about this, not Python itself.
> 
> I suppose it could be a Pylint problem...?
> 

Does calling the super __init__ function solve the PyLint issue?

super(self).__init__()

The old style/new style classes were introduced, I think, in Python
2.2 (I have not checked).

I'll check what we are doing in gdb.Function. But I've never linted
the Python bindings so there might be other areas where the linting
function flags usage requirements.

Cheers

Phil


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Python gdb.Function is an old-style class?
  2016-07-21 18:50     ` Phil Muldoon
@ 2016-07-21 19:13       ` Paul_Koning
  2016-07-21 19:17       ` Paul Smith
  1 sibling, 0 replies; 9+ messages in thread
From: Paul_Koning @ 2016-07-21 19:13 UTC (permalink / raw)
  To: pmuldoon; +Cc: psmith, gdb


> On Jul 21, 2016, at 2:49 PM, Phil Muldoon <pmuldoon@redhat.com> wrote:
> 
> ...
> I'll check what we are doing in gdb.Function. But I've never linted
> the Python bindings so there might be other areas where the linting
> function flags usage requirements.

I wonder about pylint.  I just tried it (what a pain...); it complains that gdb doesn't have a Function member [sic] even though clearly it does.

	paul


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Python gdb.Function is an old-style class?
  2016-07-21 18:50     ` Phil Muldoon
  2016-07-21 19:13       ` Paul_Koning
@ 2016-07-21 19:17       ` Paul Smith
  2016-07-21 19:20         ` Paul Smith
  2016-07-21 19:26         ` Phil Muldoon
  1 sibling, 2 replies; 9+ messages in thread
From: Paul Smith @ 2016-07-21 19:17 UTC (permalink / raw)
  To: Phil Muldoon, Paul_Koning; +Cc: gdb

On Thu, 2016-07-21 at 19:49 +0100, Phil Muldoon wrote:
> Does calling the super __init__ function solve the PyLint issue?
> 
> super(self).__init__()
> 
> The old style/new style classes were introduced, I think, in Python
> 2.2 (I have not checked).

Yes, I believe you're right.  I assume GDB doesn't try to support any
Python API older than 2.2!!

> I'll check what we are doing in gdb.Function. But I've never linted
> the Python bindings so there might be other areas where the linting
> function flags usage requirements.

I really must have fubar'ed my email to cause so much confusion :).

I have a set of functions in my own source directory like this:

  $ cat mystuff.py

  class MyStuff(gdb.Function):
      def __init__(self):
          super(MyStuff, self).__init__("mystuff")

      def invoke(self):
          do_stuff()

This works great, I can source these from within GDB then call
$mystuff() etc.

But when I run Pylint on "mystuff.py", I get an error because Pylint
thinks that I'm not inheriting from object.

I suspect a Pylint problem, where it can't grok that gdb.Function is a
new-style class (through the C API?), because the super() code actually
works.

Changing the above to the below works and satisfies Pylint, and for my
purposes (so far) it's equivalent, so it's not the end of the world:

  class MyStuff(gdb.Function):
      def __init__(self):
         
gdb.Function.__init__(self, "mystuff")

      def invoke(self):
          do_stuff()


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Python gdb.Function is an old-style class?
  2016-07-21 19:17       ` Paul Smith
@ 2016-07-21 19:20         ` Paul Smith
  2016-07-21 19:26         ` Phil Muldoon
  1 sibling, 0 replies; 9+ messages in thread
From: Paul Smith @ 2016-07-21 19:20 UTC (permalink / raw)
  To: Phil Muldoon, Paul_Koning; +Cc: gdb

Meh, Evolution formatting fail; the "works" example should of course
be:

>   class MyStuff(gdb.Function):
>       def __init__(self):
>          gdb.Function.__init__(self, "mystuff")
> 
>       def invoke(self):
>           do_stuff()


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Python gdb.Function is an old-style class?
  2016-07-21 19:17       ` Paul Smith
  2016-07-21 19:20         ` Paul Smith
@ 2016-07-21 19:26         ` Phil Muldoon
  1 sibling, 0 replies; 9+ messages in thread
From: Phil Muldoon @ 2016-07-21 19:26 UTC (permalink / raw)
  To: psmith, Paul_Koning; +Cc: gdb

On 21/07/16 20:16, Paul Smith wrote:
> On Thu, 2016-07-21 at 19:49 +0100, Phil Muldoon wrote:
>> Does calling the super __init__ function solve the PyLint issue?
>>
>> super(self).__init__()
>>
>> The old style/new style classes were introduced, I think, in Python
>> 2.2 (I have not checked).
> 
> Yes, I believe you're right.  I assume GDB doesn't try to support any
> Python API older than 2.2!!

It's ambivalent in my opinion. It works with Python 3. But I think the
case here is that nobody has run the PyLint over GDB Python API script
usage to check for these scenarios.

>> I'll check what we are doing in gdb.Function. But I've never linted
>> the Python bindings so there might be other areas where the linting
>> function flags usage requirements.
> 
> I really must have fubar'ed my email to cause so much confusion :).
> 
> I have a set of functions in my own source directory like this:
> 
>   $ cat mystuff.py
> 
>   class MyStuff(gdb.Function):
>       def __init__(self):
>           super(MyStuff, self).__init__("mystuff")
> 
>       def invoke(self):
>           do_stuff()
> 
> This works great, I can source these from within GDB then call
> $mystuff() etc.
> 
> But when I run Pylint on "mystuff.py", I get an error because Pylint
> thinks that I'm not inheriting from object.
> 
> I suspect a Pylint problem, where it can't grok that gdb.Function is a
> new-style class (through the C API?), because the super() code actually
> works.

Yes, in the source tree see gdb/python/py-function.c. I've not had a
chance to check it yet or if, in fact, there is something we could
tweak. It's never come up before ;)

Cheers

Phil


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-07-21 19:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-21 17:22 Python gdb.Function is an old-style class? Paul Smith
2016-07-21 17:38 ` Paul_Koning
2016-07-21 18:06   ` Paul_Koning
2016-07-21 18:37   ` Paul Smith
2016-07-21 18:50     ` Phil Muldoon
2016-07-21 19:13       ` Paul_Koning
2016-07-21 19:17       ` Paul Smith
2016-07-21 19:20         ` Paul Smith
2016-07-21 19:26         ` Phil Muldoon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox