2024-08-03

【備忘録】Python の Ellipsis

英辞郎 on the WEB によると、ellipsis とは「省略」あるいは「省略記号」という意味の英語の名詞です [1]。Python には、この Ellipsis あるいは ... という、省略をあらわす定数があります。

Python のマニュアル [2] によると、

Ellipsis
省略をあらわすリテラル "..." と同じです。主に拡張スライス構文やユーザ定義のコンテナデータ型において使われる特殊な値です。Ellipsistypes.EllipsisType 型の唯一のインスタンスです。

とあります。

Ellipsis は定数ですから、変数に代入できます。

a = Ellipsis
print(a, type(a))
Ellipsis <class 'ellipsis'>

あるいは、

b = ...
print(b, type(b))
Ellipsis <class 'ellipsis'>

Ellipsis の具体的な使い方は、参考サイト [3][4] に詳しく紹介されています。

Python の Ellipsis を備忘録にした動機は、PySide6 で QTableView のモデルを作成する際に QAbstractItemModel のコードを調べたところ、下記のように ... が大量に使用されていました。これを見て、なるほどと思い、あらためて確認したいと思ったからです。

class QAbstractItemModel(PySide6.QtCore.QObject):

    columnsAboutToBeInserted : ClassVar[Signal] = ... # columnsAboutToBeInserted(QModelIndex,int,int)
    columnsAboutToBeMoved    : ClassVar[Signal] = ... # columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)
    columnsAboutToBeRemoved  : ClassVar[Signal] = ... # columnsAboutToBeRemoved(QModelIndex,int,int)
    columnsInserted          : ClassVar[Signal] = ... # columnsInserted(QModelIndex,int,int)
    columnsMoved             : ClassVar[Signal] = ... # columnsMoved(QModelIndex,int,int,QModelIndex,int)
    columnsRemoved           : ClassVar[Signal] = ... # columnsRemoved(QModelIndex,int,int)
    dataChanged              : ClassVar[Signal] = ... # dataChanged(QModelIndex,QModelIndex,QList>int>); dataChanged(QModelIndex,QModelIndex)
    headerDataChanged        : ClassVar[Signal] = ... # headerDataChanged(Qt::Orientation,int,int)
    layoutAboutToBeChanged   : ClassVar[Signal] = ... # layoutAboutToBeChanged(); layoutAboutToBeChanged(QList>QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint); layoutAboutToBeChanged(QList>QPersistentModelIndex>)
    layoutChanged            : ClassVar[Signal] = ... # layoutChanged(); layoutChanged(QList>QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint); layoutChanged(QList>QPersistentModelIndex>)
    modelAboutToBeReset      : ClassVar[Signal] = ... # modelAboutToBeReset()
    modelReset               : ClassVar[Signal] = ... # modelReset()
    rowsAboutToBeInserted    : ClassVar[Signal] = ... # rowsAboutToBeInserted(QModelIndex,int,int)
    rowsAboutToBeMoved       : ClassVar[Signal] = ... # rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)
    rowsAboutToBeRemoved     : ClassVar[Signal] = ... # rowsAboutToBeRemoved(QModelIndex,int,int)
    rowsInserted             : ClassVar[Signal] = ... # rowsInserted(QModelIndex,int,int)
    rowsMoved                : ClassVar[Signal] = ... # rowsMoved(QModelIndex,int,int,QModelIndex,int)
    rowsRemoved              : ClassVar[Signal] = ... # rowsRemoved(QModelIndex,int,int)

    class CheckIndexOption(enum.Flag):

        NoOption                 : QAbstractItemModel.CheckIndexOption = ... # 0x0
        IndexIsValid             : QAbstractItemModel.CheckIndexOption = ... # 0x1
        DoNotUseParent           : QAbstractItemModel.CheckIndexOption = ... # 0x2
        ParentIsInvalid          : QAbstractItemModel.CheckIndexOption = ... # 0x4

    class LayoutChangeHint(enum.Enum):

        NoLayoutChangeHint       : QAbstractItemModel.LayoutChangeHint = ... # 0x0
        VerticalSortHint         : QAbstractItemModel.LayoutChangeHint = ... # 0x1
        HorizontalSortHint       : QAbstractItemModel.LayoutChangeHint = ... # 0x2


    def __init__(self, parent: Optional[PySide6.QtCore.QObject] = ...) -> None: ...

    def beginInsertColumns(self, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], first: int, last: int) -> None: ...
    def beginInsertRows(self, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], first: int, last: int) -> None: ...
    def beginMoveColumns(self, sourceParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], sourceFirst: int, sourceLast: int, destinationParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], destinationColumn: int) -> bool: ...
    def beginMoveRows(self, sourceParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], sourceFirst: int, sourceLast: int, destinationParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], destinationRow: int) -> bool: ...
    def beginRemoveColumns(self, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], first: int, last: int) -> None: ...
    def beginRemoveRows(self, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], first: int, last: int) -> None: ...
    def beginResetModel(self) -> None: ...
    def buddy(self, index: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> PySide6.QtCore.QModelIndex: ...
    def canDropMimeData(self, data: PySide6.QtCore.QMimeData, action: PySide6.QtCore.Qt.DropAction, row: int, column: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> bool: ...
    def canFetchMore(self, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> bool: ...
    def changePersistentIndex(self, from_: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], to: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> None: ...
    def changePersistentIndexList(self, from_: Sequence[PySide6.QtCore.QModelIndex], to: Sequence[PySide6.QtCore.QModelIndex]) -> None: ...
    def checkIndex(self, index: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], options: PySide6.QtCore.QAbstractItemModel.CheckIndexOption = ...) -> bool: ...
    def clearItemData(self, index: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> bool: ...
    def columnCount(self, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> int: ...
    @overload
    def createIndex(self, row: int, column: int, id: int = ...) -> PySide6.QtCore.QModelIndex: ...
    @overload
    def createIndex(self, row: int, column: int, ptr: object) -> PySide6.QtCore.QModelIndex: ...
    def data(self, index: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], role: int = ...) -> Any: ...
    def decodeData(self, row: int, column: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], stream: PySide6.QtCore.QDataStream) -> bool: ...
    def dropMimeData(self, data: PySide6.QtCore.QMimeData, action: PySide6.QtCore.Qt.DropAction, row: int, column: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> bool: ...
    def encodeData(self, indexes: Sequence[PySide6.QtCore.QModelIndex], stream: PySide6.QtCore.QDataStream) -> None: ...
    def endInsertColumns(self) -> None: ...
    def endInsertRows(self) -> None: ...
    def endMoveColumns(self) -> None: ...
    def endMoveRows(self) -> None: ...
    def endRemoveColumns(self) -> None: ...
    def endRemoveRows(self) -> None: ...
    def endResetModel(self) -> None: ...
    def fetchMore(self, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> None: ...
    def flags(self, index: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> PySide6.QtCore.Qt.ItemFlag: ...
    def hasChildren(self, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def hasIndex(self, row: int, column: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def headerData(self, section: int, orientation: PySide6.QtCore.Qt.Orientation, role: int = ...) -> Any: ...
    def index(self, row: int, column: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> PySide6.QtCore.QModelIndex: ...
    def insertColumn(self, column: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def insertColumns(self, column: int, count: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def insertRow(self, row: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def insertRows(self, row: int, count: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def itemData(self, index: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> Dict[int, Any]: ...
    def match(self, start: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], role: int, value: Any, hits: int = ..., flags: PySide6.QtCore.Qt.MatchFlag = ...) -> List[PySide6.QtCore.QModelIndex]: ...
    def mimeData(self, indexes: Sequence[PySide6.QtCore.QModelIndex]) -> PySide6.QtCore.QMimeData: ...
    def mimeTypes(self) -> List[str]: ...
    def moveColumn(self, sourceParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], sourceColumn: int, destinationParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], destinationChild: int) -> bool: ...
    def moveColumns(self, sourceParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], sourceColumn: int, count: int, destinationParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], destinationChild: int) -> bool: ...
    def moveRow(self, sourceParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], sourceRow: int, destinationParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], destinationChild: int) -> bool: ...
    def moveRows(self, sourceParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], sourceRow: int, count: int, destinationParent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], destinationChild: int) -> bool: ...
    @overload
    def parent(self) -> PySide6.QtCore.QObject: ...
    @overload
    def parent(self, child: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> PySide6.QtCore.QModelIndex: ...
    def persistentIndexList(self) -> List[PySide6.QtCore.QModelIndex]: ...
    def removeColumn(self, column: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def removeColumns(self, column: int, count: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def removeRow(self, row: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def removeRows(self, row: int, count: int, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> bool: ...
    def resetInternalData(self) -> None: ...
    def revert(self) -> None: ...
    def roleNames(self) -> Dict[int, PySide6.QtCore.QByteArray]: ...
    def rowCount(self, parent: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> int: ...
    def setData(self, index: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], value: Any, role: int = ...) -> bool: ...
    def setHeaderData(self, section: int, orientation: PySide6.QtCore.Qt.Orientation, value: Any, role: int = ...) -> bool: ...
    def setItemData(self, index: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex], roles: Dict[int, Any]) -> bool: ...
    def sibling(self, row: int, column: int, idx: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> PySide6.QtCore.QModelIndex: ...
    def sort(self, column: int, order: PySide6.QtCore.Qt.SortOrder = ...) -> None: ...
    def span(self, index: Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex]) -> PySide6.QtCore.QSize: ...
    def submit(self) -> bool: ...
    def supportedDragActions(self) -> PySide6.QtCore.Qt.DropAction: ...
    def supportedDropActions(self) -> PySide6.QtCore.Qt.DropAction: ...

参考サイト

  1. ellipsisの意味・使い方・読み方|英辞郎 on the WEB
  2. Built-in Constants — Python 3.12.4 documentation
  3. Python: Ellipsis について - CUBE SUGAR CONTAINER [2016-06-26]
  4. NumPy配列ndarrayの次元をEllipsis(...)で省略して指定 | note.nkmk.me

 

ブログランキング・にほんブログ村へ bitWalk's - にほんブログ村 にほんブログ村 IT技術ブログ オープンソースへ
にほんブログ村

オープンソース - ブログ村ハッシュタグ
#オープンソース



このエントリーをはてなブックマークに追加

0 件のコメント: