Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. TypeError with PySide 6.5.0 for multiple inheritance of MainWindow
Forum Updated to NodeBB v4.3 + New Features

TypeError with PySide 6.5.0 for multiple inheritance of MainWindow

Scheduled Pinned Locked Moved Solved Qt for Python
28 Posts 5 Posters 8.6k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JonBJ JonB

    @StarterKit
    If you replace your
    QMainWindow.__init__(self, parent=None)
    by
    super().__init__(self, parent=None) [Should not have self as per @SGaist below.]
    does it make the problem go away?

    If that does not solve, not that you should have to but try omitting the , parent=None in both the QMainWindow and the super() cases.

    SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by SGaist
    #8

    @JonB said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

    @StarterKit
    If you replace your
    QMainWindow.__init__(self, parent=None)
    by
    super().__init__(self, parent=None)
    does it make the problem go away?

    This is wrong, self shall not be part of the arguments passed to the function called when using super.

    super().__init__(parent=parent)
    

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    JonBJ 1 Reply Last reply
    0
    • SGaistS SGaist

      @JonB said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

      @StarterKit
      If you replace your
      QMainWindow.__init__(self, parent=None)
      by
      super().__init__(self, parent=None)
      does it make the problem go away?

      This is wrong, self shall not be part of the arguments passed to the function called when using super.

      super().__init__(parent=parent)
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #9

      @SGaist Damn, sorry, corrected. I thought I remembered Python :)

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @SGaist Damn, sorry, corrected. I thought I remembered Python :)

        S Offline
        S Offline
        StarterKit
        wrote on last edited by StarterKit
        #10

        @JonB , @SGaist , thanks for your proposal, but probably my message was not clear enough. I tried this code already and it fails with the same error unfortunately :(

          File "main.py", line 10, in __init__
            super().__init__(parent=None)
        TypeError: object.__init__() takes exactly one argument (the instance to initialize)
        

        It only works if I put nothing:

        super().__init__()
        

        but... in this case I have a failure in another part of my code... (I'm still looking into it but it appears without parent=None some other widget behaves wrong...)

        S 1 Reply Last reply
        0
        • S StarterKit

          @JonB , @SGaist , thanks for your proposal, but probably my message was not clear enough. I tried this code already and it fails with the same error unfortunately :(

            File "main.py", line 10, in __init__
              super().__init__(parent=None)
          TypeError: object.__init__() takes exactly one argument (the instance to initialize)
          

          It only works if I put nothing:

          super().__init__()
          

          but... in this case I have a failure in another part of my code... (I'm still looking into it but it appears without parent=None some other widget behaves wrong...)

          S Offline
          S Offline
          StarterKit
          wrote on last edited by
          #11

          Ok, I found why I my code fails if I use super().__init__().
          It happens because I have the same problem in another place... And I don't have a clear idea how to fix it in an easy way.

          So, I use python logging module in my app. Traditionally it prints messages to a console by default. You may redirect it to file or something else.

          But you may do whatever you want if you create you own handler and pass it to logging.addHandler() method. But your handler should be a descendant of logging.Handler.

          So, I use Qt to have GUI and I deciced to put logging output into a Plain text editor.
          As result I created a class that is descendant of both - QPlainTextEdit and logging.Handler:

          class LogViewer(QPlainTextEdit, logging.Handler):
              def __init__(self, parent=None):
                  QPlainTextEdit.__init__(self, parent)
                  logging.Handler.__init__(self)
                  # Other initialization
          
              def emit(self, record, **kwargs):
                  # log record handling
          

          and then I use it:

          self.Logs = LogViewer(parent_widget)
          self.logger = logging.getLogger()
          self.logger.addHandler(self.Logs)
          

          And as result I have exactly the same prolem TypeError: Level not an integer or a valid string because now it tries to pass parent_widget to logging.Handler constructor.

          S 1 Reply Last reply
          0
          • S StarterKit

            Ok, I found why I my code fails if I use super().__init__().
            It happens because I have the same problem in another place... And I don't have a clear idea how to fix it in an easy way.

            So, I use python logging module in my app. Traditionally it prints messages to a console by default. You may redirect it to file or something else.

            But you may do whatever you want if you create you own handler and pass it to logging.addHandler() method. But your handler should be a descendant of logging.Handler.

            So, I use Qt to have GUI and I deciced to put logging output into a Plain text editor.
            As result I created a class that is descendant of both - QPlainTextEdit and logging.Handler:

            class LogViewer(QPlainTextEdit, logging.Handler):
                def __init__(self, parent=None):
                    QPlainTextEdit.__init__(self, parent)
                    logging.Handler.__init__(self)
                    # Other initialization
            
                def emit(self, record, **kwargs):
                    # log record handling
            

            and then I use it:

            self.Logs = LogViewer(parent_widget)
            self.logger = logging.getLogger()
            self.logger.addHandler(self.Logs)
            

            And as result I have exactly the same prolem TypeError: Level not an integer or a valid string because now it tries to pass parent_widget to logging.Handler constructor.

            S Offline
            S Offline
            StarterKit
            wrote on last edited by StarterKit
            #12

            Should I have

            super(QPlainTextEdit, self).__init__(parent)
            super(logging.Handler, self).__init__()
            

            instead of:

            QPlainTextEdit.__init__(self, parent)
            logging.Handler.__init__(self)
            

            ?

            JonBJ 1 Reply Last reply
            0
            • S StarterKit

              Should I have

              super(QPlainTextEdit, self).__init__(parent)
              super(logging.Handler, self).__init__()
              

              instead of:

              QPlainTextEdit.__init__(self, parent)
              logging.Handler.__init__(self)
              

              ?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #13

              @StarterKit

              @SGaist said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

              This is wrong, self shall not be part of the arguments passed to the function called when using super.
              super().init(parent=parent)

              That's what he said. I'm not sure enough about my Python to answer, maybe no harm in trying :)

              It would be interesting to know if there is a PyQt6.5.0 and how it handles your existing code. You say it was working at 6.4.3, I don't know whether the PySide 6.5 is correct or not.

              For the architecture of this particular logger case. Since you have to derive from logging.Handler, why don't you encapsulate the QPlainTextEdit in your class instead of multiple-inheriting from it? My initial thought is that would be preferable. Then you would not multiple-inherit and you wouldn't have the current problem, whatever it is.

              S 2 Replies Last reply
              1
              • JonBJ JonB

                @StarterKit

                @SGaist said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

                This is wrong, self shall not be part of the arguments passed to the function called when using super.
                super().init(parent=parent)

                That's what he said. I'm not sure enough about my Python to answer, maybe no harm in trying :)

                It would be interesting to know if there is a PyQt6.5.0 and how it handles your existing code. You say it was working at 6.4.3, I don't know whether the PySide 6.5 is correct or not.

                For the architecture of this particular logger case. Since you have to derive from logging.Handler, why don't you encapsulate the QPlainTextEdit in your class instead of multiple-inheriting from it? My initial thought is that would be preferable. Then you would not multiple-inherit and you wouldn't have the current problem, whatever it is.

                S Offline
                S Offline
                StarterKit
                wrote on last edited by StarterKit
                #14

                @JonB, I've created PYSIDE-2294 where I try to figure out how my code should look like...
                The main strange thing indeed is that everything is fine with 6.4.3 and goes to hell with 6.5.0. I'm not a python master but... it worked pretty well before 6.5.0 even if my code isn't ideal :)

                With regards to your question about inheritance. I use Qt Designer to create UI layout. So for me it is easier to have Qt-based class that I may use in Qt Designer and simply put an object on form with help of mouse. This is why I inherited from QPlainTextEdit.
                I may do it other way around and make another class that would be derived from logging.Handler and then use it as a member of my class. But these two classes will be tightly coupled and won't work one without another.
                So... if one way I lose benefits of Qt, another way I have bad design... - and then, why would we have multiple inheritance at all? :) I created this class some time ago and it survived migration from Qt 5 to Qt 6... But now it fails with Qt 6.5.0 :(

                S 1 Reply Last reply
                0
                • S StarterKit

                  @JonB, I've created PYSIDE-2294 where I try to figure out how my code should look like...
                  The main strange thing indeed is that everything is fine with 6.4.3 and goes to hell with 6.5.0. I'm not a python master but... it worked pretty well before 6.5.0 even if my code isn't ideal :)

                  With regards to your question about inheritance. I use Qt Designer to create UI layout. So for me it is easier to have Qt-based class that I may use in Qt Designer and simply put an object on form with help of mouse. This is why I inherited from QPlainTextEdit.
                  I may do it other way around and make another class that would be derived from logging.Handler and then use it as a member of my class. But these two classes will be tightly coupled and won't work one without another.
                  So... if one way I lose benefits of Qt, another way I have bad design... - and then, why would we have multiple inheritance at all? :) I created this class some time ago and it survived migration from Qt 5 to Qt 6... But now it fails with Qt 6.5.0 :(

                  S Offline
                  S Offline
                  StarterKit
                  wrote on last edited by StarterKit
                  #15

                  Hi all,
                  So it appears to be a bug introduced in PySide 6.5.0 release that they corrected as result of PYSIDE-2294.

                  But I try to understand how super() works based on information that I collected.
                  And I'm a bit puzzled now...
                  Here is my old code:

                  import logging
                  from PySide6.QtWidgets import QApplication, QPlainTextEdit
                  
                  class LogViewer(QPlainTextEdit, logging.Handler):
                      def __init__(self, parent=None):
                          QPlainTextEdit.__init__(self, parent)     # this line will be changed
                          logging.Handler.__init__(self)            # this line will be changed
                  
                  app = QApplication([])
                  window = LogViewer()
                  window.show()
                  print(f"LEVEL: {window.level}")
                  app.exec() 
                  

                  It works and prints LEVEL: 0 as expected.
                  But based on all these discussions I decided to change it and use super() and got this code:

                  import logging
                  from PySide6.QtWidgets import QApplication, QPlainTextEdit
                  
                  class LogViewer(QPlainTextEdit, logging.Handler):
                      def __init__(self, parent=None):
                          super().__init__(parent=parent)     # this line was changed
                  
                  app = QApplication([])
                  window = LogViewer()
                  window.show()
                  print(f"LEVEL: {window.level}")
                  app.exec() 
                  

                  And this code fails with AttributeError: 'LogViewer' object has no attribute 'level' - it appears that logging.Handler ancestor didn't become a part of window object... I don't understand what is wrong in this case... Any hints?...

                  I played a bit and changed 2nd example to use different class order: class LogViewer(logging.Handler, QPlainTextEdit) and it gave me TypeError: Handler.__init__() got an unexpected keyword argument 'parent' that raises a feeling that something is not right...

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @StarterKit

                    @SGaist said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

                    This is wrong, self shall not be part of the arguments passed to the function called when using super.
                    super().init(parent=parent)

                    That's what he said. I'm not sure enough about my Python to answer, maybe no harm in trying :)

                    It would be interesting to know if there is a PyQt6.5.0 and how it handles your existing code. You say it was working at 6.4.3, I don't know whether the PySide 6.5 is correct or not.

                    For the architecture of this particular logger case. Since you have to derive from logging.Handler, why don't you encapsulate the QPlainTextEdit in your class instead of multiple-inheriting from it? My initial thought is that would be preferable. Then you would not multiple-inherit and you wouldn't have the current problem, whatever it is.

                    S Offline
                    S Offline
                    StarterKit
                    wrote on last edited by
                    #16

                    @JonB said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

                    For the architecture of this particular logger case. Since you have to derive from logging.Handler, why don't you encapsulate the QPlainTextEdit in your class instead of multiple-inheriting from it? My initial thought is that would be preferable. Then you would not multiple-inherit and you wouldn't have the current problem, whatever it is.

                    Finally I decided to encaplusate logging.Handler in my class and now I like it more than before :)
                    The bug was confirmed in PySide and to be corrected in future versions but everything works good without multiple inheritance.

                    Also initial code was not ideal and was different from Qt recommendations.

                    So, with both things changed I have my code up and running again.

                    JonBJ 1 Reply Last reply
                    1
                    • S StarterKit has marked this topic as solved on
                    • S StarterKit

                      @JonB said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

                      For the architecture of this particular logger case. Since you have to derive from logging.Handler, why don't you encapsulate the QPlainTextEdit in your class instead of multiple-inheriting from it? My initial thought is that would be preferable. Then you would not multiple-inherit and you wouldn't have the current problem, whatever it is.

                      Finally I decided to encaplusate logging.Handler in my class and now I like it more than before :)
                      The bug was confirmed in PySide and to be corrected in future versions but everything works good without multiple inheritance.

                      Also initial code was not ideal and was different from Qt recommendations.

                      So, with both things changed I have my code up and running again.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #17

                      @StarterKit said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

                      Finally I decided to encaplusate logging.Handler in my class and now I like it more than before :)

                      That is indeed the best, but earlier you said

                      But your handler should be a descendant of logging.Handler.

                      Anyway, sounds good :)

                      S 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @StarterKit said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

                        Finally I decided to encaplusate logging.Handler in my class and now I like it more than before :)

                        That is indeed the best, but earlier you said

                        But your handler should be a descendant of logging.Handler.

                        Anyway, sounds good :)

                        S Offline
                        S Offline
                        StarterKit
                        wrote on last edited by
                        #18

                        @JonB said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

                        That is indeed the best, but earlier you said

                        I thought one more time about it and decided that there is a better desing option possible :) Not a big change but I moved 2 more methods inside my class and it looks good after all :)

                        1 Reply Last reply
                        1
                        • J Offline
                          J Offline
                          jonton
                          wrote on last edited by
                          #19

                          We have hit this issue too. PySide 6.5.0 appears to use the signature of the last super-class that is initialised for both of them. The example we have is:

                              def __init__(self, rootDataModel, parent):
                                  super(QtCore.QObject, self).__init__(self)
                                  StateSource.__init__(self, parent, "model")
                          

                          This results in a runtime error of:

                              QtCore.QObject.__init__(self)
                          TypeError:__init__() missing 2 required positional arguments: 'parent' and 'name'
                          

                          If I reverse the order of initialisation to:

                              def __init__(self, rootDataModel, parent):
                                  StateSource.__init__(self, parent, "model")
                                  super(QtCore.QObject, self).__init__(self)
                          

                          Then the error reports that the StateSource initialiser only should have a single parameter.

                          J 1 Reply Last reply
                          0
                          • J jonton

                            We have hit this issue too. PySide 6.5.0 appears to use the signature of the last super-class that is initialised for both of them. The example we have is:

                                def __init__(self, rootDataModel, parent):
                                    super(QtCore.QObject, self).__init__(self)
                                    StateSource.__init__(self, parent, "model")
                            

                            This results in a runtime error of:

                                QtCore.QObject.__init__(self)
                            TypeError:__init__() missing 2 required positional arguments: 'parent' and 'name'
                            

                            If I reverse the order of initialisation to:

                                def __init__(self, rootDataModel, parent):
                                    StateSource.__init__(self, parent, "model")
                                    super(QtCore.QObject, self).__init__(self)
                            

                            Then the error reports that the StateSource initialiser only should have a single parameter.

                            J Offline
                            J Offline
                            jonton
                            wrote on last edited by
                            #20

                            @jonton

                            This makes me think it's a new bug that has been introduced into the handling of multiple inheritance in PySide.

                            I don't know enough about the inner workings of PySide, perhaps someone on this forum can shed some light on it?

                            JonBJ 1 Reply Last reply
                            0
                            • J jonton

                              @jonton

                              This makes me think it's a new bug that has been introduced into the handling of multiple inheritance in PySide.

                              I don't know enough about the inner workings of PySide, perhaps someone on this forum can shed some light on it?

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #21

                              @jonton
                              There was some "fix" for 6.5.0/6.6.0 in https://bugreports.qt.io/browse/PYSIDE-2294, though I don't know what was "fixed" exactly.
                              Have you read that one? Should you comment there?

                              J 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @jonton
                                There was some "fix" for 6.5.0/6.6.0 in https://bugreports.qt.io/browse/PYSIDE-2294, though I don't know what was "fixed" exactly.
                                Have you read that one? Should you comment there?

                                J Offline
                                J Offline
                                jonton
                                wrote on last edited by
                                #22

                                Thanks @JonB

                                That does sound like the same issue, but as you say it's not clear in the discussion whether there is actually a fix in 6.6.0 or not?

                                I'll check in with them there.

                                Cheers,

                                Jon

                                JonBJ 1 Reply Last reply
                                0
                                • J jonton

                                  Thanks @JonB

                                  That does sound like the same issue, but as you say it's not clear in the discussion whether there is actually a fix in 6.6.0 or not?

                                  I'll check in with them there.

                                  Cheers,

                                  Jon

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by JonB
                                  #23

                                  @jonton
                                  It is deffo the same issue! :) It was reported against 6.4. I don't understand because I read it as it was "fixed" in both 6.5.0 & 6.6.0, whatever fixing in "both" means, but I think you are saying you are having a problem in 6.5. I don't know whether that is the original problem OR they did some fix for that which you have, but now you have/that has introduced a (new?) problem with your super() case.

                                  J 1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @jonton
                                    It is deffo the same issue! :) It was reported against 6.4. I don't understand because I read it as it was "fixed" in both 6.5.0 & 6.6.0, whatever fixing in "both" means, but I think you are saying you are having a problem in 6.5. I don't know whether that is the original problem OR they did some fix for that which you have, but now you have/that has introduced a (new?) problem with your super() case.

                                    J Offline
                                    J Offline
                                    jonton
                                    wrote on last edited by jonton
                                    #24

                                    I'm certainly having the problem in 6.5.0, whereas the code works in 6.4.3 correctly.

                                    It looks like the change that came into 6.5.0 was this:

                                    https://github.com/pyside/pyside-setup/commit/e8095467f7d0332cc0987e7c541de9906e19fece

                                    And this has caused the regression?

                                    JonBJ 1 Reply Last reply
                                    0
                                    • J jonton

                                      I'm certainly having the problem in 6.5.0, whereas the code works in 6.4.3 correctly.

                                      It looks like the change that came into 6.5.0 was this:

                                      https://github.com/pyside/pyside-setup/commit/e8095467f7d0332cc0987e7c541de9906e19fece

                                      And this has caused the regression?

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by JonB
                                      #25

                                      @jonton
                                      I would not begin to know the implications of the changes you see.

                                      It sounds like:

                                      • There was a problem with multiple inheritance at 6.4 which they fixed at 6.5, or they just changed/improved it, per the changes.

                                      • Now at 6.5 that may be fixed/improved, but other cases, such as yours and @StarterKit's, go wrong, where they used to be OK at 6.4.

                                      I do not truly understand the discussion in https://bugreports.qt.io/browse/PYSIDE-2294 or what the conclusion was. You may need to post there, or raise a new issue.

                                      One thing: I see you use super(QtCore.QObject, self).__init__(self) in both your cases. But @SGaist wrote

                                      This is wrong, self shall not be part of the arguments passed to the function called when using super.
                                      super().init(parent=parent)

                                      So is not that the issue?

                                      At this point I am passing here, as it's becoming a Python issue I am not sufficiently familiar with.

                                      J 1 Reply Last reply
                                      0
                                      • JonBJ JonB

                                        @jonton
                                        I would not begin to know the implications of the changes you see.

                                        It sounds like:

                                        • There was a problem with multiple inheritance at 6.4 which they fixed at 6.5, or they just changed/improved it, per the changes.

                                        • Now at 6.5 that may be fixed/improved, but other cases, such as yours and @StarterKit's, go wrong, where they used to be OK at 6.4.

                                        I do not truly understand the discussion in https://bugreports.qt.io/browse/PYSIDE-2294 or what the conclusion was. You may need to post there, or raise a new issue.

                                        One thing: I see you use super(QtCore.QObject, self).__init__(self) in both your cases. But @SGaist wrote

                                        This is wrong, self shall not be part of the arguments passed to the function called when using super.
                                        super().init(parent=parent)

                                        So is not that the issue?

                                        At this point I am passing here, as it's becoming a Python issue I am not sufficiently familiar with.

                                        J Offline
                                        J Offline
                                        jonton
                                        wrote on last edited by
                                        #26

                                        @JonB

                                        Thanks for all the help with this, it's been invaluable. I found the root cause of our problem. The order that the base classes are inherited in affects the Method Resolution Order, which confuses the new system.

                                        I think it points to an error in PySide 6.5.0, but I don't have enough knowledge of the inner workings of Python and PySide to make a call on this. I'll put a note on the issue page that you pointed to.

                                        The PR to fix this in USD is here, which goes into an explanation of the issue:

                                        https://github.com/PixarAnimationStudios/USD/pull/2392

                                        JonBJ 1 Reply Last reply
                                        1
                                        • J jonton

                                          @JonB

                                          Thanks for all the help with this, it's been invaluable. I found the root cause of our problem. The order that the base classes are inherited in affects the Method Resolution Order, which confuses the new system.

                                          I think it points to an error in PySide 6.5.0, but I don't have enough knowledge of the inner workings of Python and PySide to make a call on this. I'll put a note on the issue page that you pointed to.

                                          The PR to fix this in USD is here, which goes into an explanation of the issue:

                                          https://github.com/PixarAnimationStudios/USD/pull/2392

                                          JonBJ Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on last edited by
                                          #27

                                          @jonton said in TypeError with PySide 6.5.0 for multiple inheritance of MainWindow:

                                          I'll put a note on the issue page that you pointed to.

                                          Please do so. I don't know whether they will say it is a 6.5.0 issue or whether they will say your code is wrong/the behaviour you see is correct.

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved