Solved Python3 WindowXML object.__init__() takes no arguments
#1
I'm using script that create custom window from windowxml, and that works fine in python2 based kodi.


class ConnectionWizard(xbmcgui.WindowXML):
  def __init__(self, xml_file, resource_path, skin, skin_res):
     xbmcgui.WindowXML.__init__(self, xml_file, resource_path, skin, skin_res, False)
    #super(ConnectionWizard, self).__init__(self, xml_file, resource_path, skin, skin_res)
    #super().__init__(self, xml_file, resource_path, skin, skin_res, False)


But in Python3 I have this issue:
TypeError: object.__init__() takes no arguments

I tried with super, super() and nothing helps (I comment them out, but included in snipe)

I would like to fix this (without importing fancy-helping-convert-modules like kodi65 and kodi-six) just pure python solution.
Proud developer for Shoko and Nakamori. Long time xbmc/kodi user. IT Freak at Monogatari.
Reply
#2
Method calls via super() do not take self as the first argument. Otherwise all this seems weird.
Raspberry PI 2 + LibreELEC 8 (Kodi 17)
Samsung Galaxy Tab A 10.1 + Kodi 17 for Android
Reply
#3
Having the same issue:

class ActionMenu(xbmcgui.WindowXMLDialog):
    def __init__(self, *args, **kwargs):
        xbmcgui.WindowXML.__init__(self, *args, **kwargs)


ERROR
TypeError: object.__init__() takes no arguments

What is the correct Python 3 way to do this?
Reply
#4
Kodi's Python classes are basically hooked up to __new__ rather than __init__, so it already has the args it needs and you don't need to pass args/kwargs down to super. Taking a quick look through my code I have always been inconsistent with this, sometimes I do pass them down and sometimes not. I feel like I had encountered this long ago even in py2.

And a quick poke through some scripts in the repo has @ronie not calling super init at all, and this neat trick. I'd say ronie has the right idea.
Reply
#5
So the suggestion is not calling it at all?
Reply
#6
@rmrector thank you for that snipped, it was clear - I first moved to xbmcgui.WindowXML.__init__(self) but then remove it completely, as it does work fine in both version - I probably never understand why I had to do it that way, but I notice that with later custom windows I stopped doing it long time ago :-) probably something that I copied while I was learning how to use windowxml.

@Roman_V_M your are a professional python developer, for you It could looked weird. Also you suggested that super does not take self as first argument, but I tried without self and the error was same, that the _init_ dont accept ANY arguments.

I ended up not calling that at all and use it more like in other languages.
Proud developer for Shoko and Nakamori. Long time xbmc/kodi user. IT Freak at Monogatari.
Reply
#7
(2019-09-10, 07:39)bigretromike Wrote: @Roman_V_M your are a professional python developer, for you It could looked weird.

Sorry for not being clear. The error itself looks weird, not your code (except for self in super). Explicit call to xbmcgui.WindowXML.__init__(self, xml_file, resource_path, skin, skin_res, False) should work.

@rmrector New-style classes (in Python 3 you have only them) must accept arguments in super() call if the respective parent class' method accept those arguments. It looks like a bug/feature in C++/Python wrapper used in Kodi where wrapped classes exposed to Python have their own type rather than being instances of the standard type.
Raspberry PI 2 + LibreELEC 8 (Kodi 17)
Samsung Galaxy Tab A 10.1 + Kodi 17 for Android
Reply
#8
(2019-09-10, 10:59)Roman_V_M Wrote:
(2019-09-10, 07:39)bigretromike Wrote: @Roman_V_M your are a professional python developer, for you It could looked weird.

Sorry for not being clear. The error itself looks weird, not your code (except for self in super). Explicit call to xbmcgui.WindowXML.__init__(self, xml_file, resource_path, skin, skin_res, False) should work.

@rmrector New-style classes (in Python 3 you have only them) must accept arguments in super() call if the respective parent class' method accept those arguments. It looks like a bug/feature in C++/Python wrapper used in Kodi where wrapped classes exposed to Python have their own type rather than being instances of the standard type

Thats what I read for most parts, that It should worked - but then again it didn't. Yet removing it fix issue and both version py2 and py3 work flawless, so I don't really know :-) but I'm happy that my project work on both versions now.
Proud developer for Shoko and Nakamori. Long time xbmc/kodi user. IT Freak at Monogatari.
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Python3 WindowXML object.__init__() takes no arguments00