久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='lV9as'><style id='lV9as'><dir id='lV9as'><q id='lV9as'></q></dir></style></legend><tfoot id='lV9as'></tfoot>
      • <bdo id='lV9as'></bdo><ul id='lV9as'></ul>

      <i id='lV9as'><tr id='lV9as'><dt id='lV9as'><q id='lV9as'><span id='lV9as'><b id='lV9as'><form id='lV9as'><ins id='lV9as'></ins><ul id='lV9as'></ul><sub id='lV9as'></sub></form><legend id='lV9as'></legend><bdo id='lV9as'><pre id='lV9as'><center id='lV9as'></center></pre></bdo></b><th id='lV9as'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lV9as'><tfoot id='lV9as'></tfoot><dl id='lV9as'><fieldset id='lV9as'></fieldset></dl></div>
    1. <small id='lV9as'></small><noframes id='lV9as'>

      1. 如何在沒有元類沖突的情況下將泛型類型與 PyQ

        How do I use generic typing with PyQt subclass without metaclass conflicts?(如何在沒有元類沖突的情況下將泛型類型與 PyQt 子類一起使用?)

      2. <tfoot id='HoeIo'></tfoot>

          • <legend id='HoeIo'><style id='HoeIo'><dir id='HoeIo'><q id='HoeIo'></q></dir></style></legend>
          • <i id='HoeIo'><tr id='HoeIo'><dt id='HoeIo'><q id='HoeIo'><span id='HoeIo'><b id='HoeIo'><form id='HoeIo'><ins id='HoeIo'></ins><ul id='HoeIo'></ul><sub id='HoeIo'></sub></form><legend id='HoeIo'></legend><bdo id='HoeIo'><pre id='HoeIo'><center id='HoeIo'></center></pre></bdo></b><th id='HoeIo'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HoeIo'><tfoot id='HoeIo'></tfoot><dl id='HoeIo'><fieldset id='HoeIo'></fieldset></dl></div>
              <tbody id='HoeIo'></tbody>

              <bdo id='HoeIo'></bdo><ul id='HoeIo'></ul>

              <small id='HoeIo'></small><noframes id='HoeIo'>

                • 本文介紹了如何在沒有元類沖突的情況下將泛型類型與 PyQt 子類一起使用?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我曾嘗試使用 sip 包裝器類型的 abc.ABCMeta,它在使用 abc.ABC 進行子類化時效果很好.

                  I had tried the abc.ABCMeta with sip wrapper type, and it works well when subclass with abc.ABC.

                  class QABCMeta(wrappertype, ABCMeta):
                      pass
                  
                  class WidgetBase(QWidget, metaclass=QABCMeta):
                      ...
                  
                  class InterfaceWidget(WidgetBase, ABC):
                      ...
                  
                  class MainWidget(InterfaceWidget):
                      ...
                  

                  但它不適用于 typing.Generic.

                  class QGenericMeta(wrappertype, GenericMeta):
                      pass
                  
                  class WidgetBase(QWidget, Generic[T], metaclass=QGenericMeta):
                      ...
                  
                  class GenericWidget(WidgetBase[float]):
                      ...
                  

                  它提出了:

                  line 980, in __new__
                      self if not origin else origin._gorg)
                  TypeError: can't apply this __setattr__ to sip.wrappertype object
                  

                  我希望它像往常一樣使用通用子類:

                  I expected it to use generic subclass as usual:

                  class TableBase(QTableWidget, Generic[T]):
                      @abstractmethod
                      def raw_item(self, row: int) -> T:
                          ...
                      def data(self) -> Iterator[T]:
                          yield from (self.raw_item(row) for row in range(self.rowCount()))
                  
                  class MainTable(TableBase[float]):
                      def raw_item(self, row: int) -> float:
                          return float(self.item(row, 1).text())  # implementation
                  
                  table = MainTable()
                  for data in table.data():
                      data: float
                  

                  但是在沒有繼承Generic[T]的情況下,data仍然是Any.

                  But the data is still Any when without inherit Generic[T].

                  可以用 PEP 560 解決類型檢查嗎?

                  Can it solved with PEP 560 to do type checking?

                  推薦答案

                  嗯,我找到了答案.

                  由于typing.Generic的元類是abc.ABC,它也應該基于abc.ABCMeta.但這僅適用于 Python 3.7 或更高版本.

                  Since the metaclass of typing.Generic is abc.ABC, it should based on abc.ABCMeta too. But this is only works with Python 3.7 or above.

                  然后,只需使用 type(QObject) 而不是 sip.wrappertype:

                  And then, just use type(QObject) instead of sip.wrappertype:

                  # -*- coding: utf-8 -*-
                  
                  from abc import abstractmethod, ABC, ABCMeta
                  from typing import TypeVar, Generic, Iterator
                  from PyQt5.QtCore import QObject
                  from PyQt5.QtWidgets import QTableWidget
                  
                  QObjectType = type(QObject)
                  T = TypeVar('T')
                  
                  
                  class QABCMeta(QObjectType, ABCMeta):
                      pass
                  
                  
                  class BaseWidget(QTableWidget, Generic[T], metaclass=QABCMeta):
                  
                      @abstractmethod
                      def raw_item(self, row: int) -> T:
                          ...
                  
                      def data(self) -> Iterator[T]:
                          yield from (self.raw_item(row) for row in range(self.rowCount()))
                  
                  
                  class TestWidget(BaseWidget[float], ABC):  # optional inherit ABC.
                  
                      def raw_item(self, row: int) -> float:
                          return float(self.item(row, 1).text())
                  
                  
                  if __name__ == '__main__':
                      w = TestWidget()
                      for f in w.data():
                          pass
                  

                  此代碼適用于PyCharm IDE,變量f的注解為float.

                  This code is works for PyCharm IDE, the annotation of variable f is float.

                  PyQt5改成PySide2也可以!

                  這篇關于如何在沒有元類沖突的情況下將泛型類型與 PyQt 子類一起使用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                    <tbody id='gkdEB'></tbody>
                  <legend id='gkdEB'><style id='gkdEB'><dir id='gkdEB'><q id='gkdEB'></q></dir></style></legend>

                    <i id='gkdEB'><tr id='gkdEB'><dt id='gkdEB'><q id='gkdEB'><span id='gkdEB'><b id='gkdEB'><form id='gkdEB'><ins id='gkdEB'></ins><ul id='gkdEB'></ul><sub id='gkdEB'></sub></form><legend id='gkdEB'></legend><bdo id='gkdEB'><pre id='gkdEB'><center id='gkdEB'></center></pre></bdo></b><th id='gkdEB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gkdEB'><tfoot id='gkdEB'></tfoot><dl id='gkdEB'><fieldset id='gkdEB'></fieldset></dl></div>
                  1. <small id='gkdEB'></small><noframes id='gkdEB'>

                    • <bdo id='gkdEB'></bdo><ul id='gkdEB'></ul>
                      • <tfoot id='gkdEB'></tfoot>

                            主站蜘蛛池模板: 中文精品一区二区 | 国产高清精品一区二区三区 | 国产激情精品一区二区三区 | 国产乱码精品一区二区三区忘忧草 | 国产成人精品免费 | 亚洲视频一 | 亚洲综合色网 | 欧美精品成人影院 | 激情小说综合网 | 99国产精品99久久久久久 | 一级电影免费看 | 免费激情av | 日韩视频―中文字幕 | 欧美一区免费 | 美女在线观看av | 精品日韩 | 国产中文字幕在线观看 | 久久精品| 三区四区在线观看 | 成人亚洲| 日本不卡免费新一二三区 | 亚洲精品在线免费观看视频 | 日操操夜操操 | 国产精品日日夜夜 | 成年人精品视频在线观看 | 成人免费视频观看视频 | 在线三级电影 | 亚洲精品乱码久久久久v最新版 | 欧美一区二区三区在线看 | 久久久123| 亚洲精品在线免费观看视频 | 精品久久久久久久久久久 | 国产精品嫩草影院精东 | 免费看一区二区三区 | 亚洲精品久久久久久国产精华液 | av中文字幕在线 | 欧美激情久久久 | 中文成人在线 | 日韩在线一区二区 | 日韩美女在线看免费观看 | 国产黄色大片在线免费观看 |