PS C:\epc\bug> venv3.7-32/scripts/python bad.py
sys.version: 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)]
sys.platform: win32
QT_VERSION_STR: 5.13.0
PYQT_VERSION_STR: 5.13.0
SIP_VERSION_STR: 4.19.18

     ------ creating WidgetC and...
getting a:
           hasattr(self, 'ui') == True
           hasattr(self.ui, 'label') == True
got a

     ------ creating WidgetC and... now it still works
getting a:
           hasattr(self, 'ui') == True
           hasattr(self.ui, 'label') == True
got a

     ------ creating WidgetB and...
getting a:
           hasattr(self, 'ui') == False
           hasattr(self, 'label') == True

     ------ creating WidgetB and... now it breaks
           hasattr(self, 'ui') == False
           hasattr(self, 'label') == True
AttributeError: __getattribute__

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "bad.py", line 135, in main
    widgets.append(WidgetB())
  File "bad.py", line 82, in __init__
    self.ui = PyQt5.uic.loadUi(io.StringIO(ui_text), self)
  File "C:\epc\bug\venv3.7-32\lib\site-packages\PyQt5\uic\__init__.py", line 227, in loadUi
    return DynamicUILoader(package).loadUi(uifile, baseinstance, resource_suffix)
  File "C:\epc\bug\venv3.7-32\lib\site-packages\PyQt5\uic\Loader\loader.py", line 72, in loadUi
    return self.parse(filename, resource_suffix, basedir)
  File "C:\epc\bug\venv3.7-32\lib\site-packages\PyQt5\uic\uiparser.py", line 1030, in parse
  File "C:\epc\bug\venv3.7-32\lib\site-packages\PyQt5\uic\uiparser.py", line 942, in createConnections
    QtCore.QMetaObject.connectSlotsByName(self.toplevelWidget)
SystemError: <built-in function connectSlotsByName> returned a result with an error set

     ------ creating WidgetA without breaking
got a
getting b
got b

     ------ creating WidgetA but breaking in the process
AttributeError: __getattribute__

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "bad.py", line 146, in main
    widgets.append(WidgetA(broken=True))
  File "bad.py", line 53, in __init__
    PyQt5.uic.loadUi(io.StringIO(ui_text), self)
  File "C:\epc\bug\venv3.7-32\lib\site-packages\PyQt5\uic\__init__.py", line 227, in loadUi
    return DynamicUILoader(package).loadUi(uifile, baseinstance, resource_suffix)
  File "C:\epc\bug\venv3.7-32\lib\site-packages\PyQt5\uic\Loader\loader.py", line 72, in loadUi
    return self.parse(filename, resource_suffix, basedir)
  File "C:\epc\bug\venv3.7-32\lib\site-packages\PyQt5\uic\uiparser.py", line 1030, in parse
    actor(elem)
  File "C:\epc\bug\venv3.7-32\lib\site-packages\PyQt5\uic\uiparser.py", line 942, in createConnections
    QtCore.QMetaObject.connectSlotsByName(self.toplevelWidget)
SystemError: <built-in function connectSlotsByName> returned a result with an error set