Skip to content

Various stub improvements and Pyright support #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ jobs:
fail-fast: false
matrix:
include:
# oldest version of pyhon / mypy which works
- python-version: "3.6"
mypy-version: "0.940"

# latest version of everything
- python-version: "3.8"
- python-version: "3.10"
mypy-version: "0.971"

steps:
- uses: actions/checkout@v3
Expand All @@ -33,9 +28,9 @@ jobs:

- name: Install dependencies
run: |
python -m pip install pip==21.1.2 # last version that works for editable install + mypy
python -m pip install pyside2 pytest mypy==${{ matrix.mypy-version }}
pip install -e .
python -m pip install --upgrade pip
python -m pip install -r dev-requirements.txt
pip install -e . --config-settings editable_mode=strict # required for mypy/pyright to detect editable install
pip list

- name: run tests
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ Here, you take all the steps to reproduce a complete stub testing environment to
5. Make your current directory an editable installed package.


pip install -e .
pip install -e . --config-settings editable_mode=strict

Note: currently, with pip 22 and above, and mypy 0.971, the editable installation is not picked by mypy.
For the CI, I need to force pip to version 21.2 for it to work. You may need to force pip also to this version.
Note: the `editable_mode` option is required for Mypy to pick up the editable installation as of recent versions of setuptools.
See https://github.com/python/mypy/issues/13392.


6. Make sure the tests run correctly as they are:
Expand Down
6 changes: 3 additions & 3 deletions PySide2-stubs/QtAxContainer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class QAxSelect(PySide2.QtWidgets.QDialog):
SandboxingProcess : QAxSelect.SandboxingLevel = ... # 0x1
SandboxingLowIntegrity : QAxSelect.SandboxingLevel = ... # 0x2

def __init__(self, parent:typing.Optional[PySide2.QtWidgets.QWidget]=..., flags:PySide2.QtCore.Qt.WindowFlags=...) -> None: ...
def __init__(self, parent:typing.Optional[PySide2.QtWidgets.QWidget]=..., flags:typing.Union[PySide2.QtCore.Qt.WindowFlags, PySide2.QtCore.Qt.WindowType]=...) -> None: ...

def clsid(self) -> str: ...
def sandboxingLevel(self) -> PySide2.QtAxContainer.QAxSelect.SandboxingLevel: ...
Expand All @@ -215,9 +215,9 @@ class QAxWidget(PySide2.QtWidgets.QWidget, PySide2.QtAxContainer.QAxBase):


@typing.overload
def __init__(self, c:str, parent:typing.Optional[PySide2.QtWidgets.QWidget]=..., f:PySide2.QtCore.Qt.WindowFlags=...) -> None: ...
def __init__(self, c:str, parent:typing.Optional[PySide2.QtWidgets.QWidget]=..., f:typing.Union[PySide2.QtCore.Qt.WindowFlags, PySide2.QtCore.Qt.WindowType]=...) -> None: ...
@typing.overload
def __init__(self, parent:typing.Optional[PySide2.QtWidgets.QWidget]=..., f:PySide2.QtCore.Qt.WindowFlags=...) -> None: ...
def __init__(self, parent:typing.Optional[PySide2.QtWidgets.QWidget]=..., f:typing.Union[PySide2.QtCore.Qt.WindowFlags, PySide2.QtCore.Qt.WindowType]=...) -> None: ...

def changeEvent(self, e:PySide2.QtCore.QEvent) -> None: ...
def className(self) -> bytes: ...
Expand Down
6 changes: 3 additions & 3 deletions PySide2-stubs/QtCharts.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,9 @@ class QtCharts(Shiboken.Object):
ChartTypePolar : QtCharts.QChart.ChartType = ... # 0x2

@typing.overload
def __init__(self, parent:typing.Optional[PySide2.QtWidgets.QGraphicsItem]=..., wFlags:PySide2.QtCore.Qt.WindowFlags=...) -> None: ...
def __init__(self, parent:typing.Optional[PySide2.QtWidgets.QGraphicsItem]=..., wFlags:typing.Union[PySide2.QtCore.Qt.WindowFlags, PySide2.QtCore.Qt.WindowType]=...) -> None: ...
@typing.overload
def __init__(self, type:PySide2.QtCharts.QtCharts.QChart.ChartType, parent:PySide2.QtWidgets.QGraphicsItem, wFlags:PySide2.QtCore.Qt.WindowFlags) -> None: ...
def __init__(self, type:PySide2.QtCharts.QtCharts.QChart.ChartType, parent:PySide2.QtWidgets.QGraphicsItem, wFlags:typing.Union[PySide2.QtCore.Qt.WindowFlags, PySide2.QtCore.Qt.WindowType]) -> None: ...

def addAxis(self, axis:PySide2.QtCharts.QtCharts.QAbstractAxis, alignment:PySide2.QtCore.Qt.Alignment) -> None: ...
def addSeries(self, series:PySide2.QtCharts.QtCharts.QAbstractSeries) -> None: ...
Expand Down Expand Up @@ -1405,7 +1405,7 @@ class QtCharts(Shiboken.Object):
def __ixor__(self, other: typing.Union[int, PolarOrientation, PolarOrientations]) -> PolarOrientations: ...
def __invert__(self) -> PolarOrientations: ...

def __init__(self, parent:typing.Optional[PySide2.QtWidgets.QGraphicsItem]=..., wFlags:PySide2.QtCore.Qt.WindowFlags=...) -> None: ...
def __init__(self, parent:typing.Optional[PySide2.QtWidgets.QGraphicsItem]=..., wFlags:typing.Union[PySide2.QtCore.Qt.WindowFlags, PySide2.QtCore.Qt.WindowType]=...) -> None: ...

@typing.overload
def addAxis(self, axis:PySide2.QtCharts.QtCharts.QAbstractAxis, alignment:PySide2.QtCore.Qt.Alignment) -> None: ...
Expand Down
166 changes: 96 additions & 70 deletions PySide2-stubs/QtCore.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ import sys
# Module PySide2.QtCore
import PySide2

import enum
import typing

import shiboken2 as Shiboken

import PySide2.QtCore

QObjectT = typing.TypeVar('QObjectT', bound='QOjbect')
QObjectT = typing.TypeVar('QObjectT', bound='QObject')

class ClassInfo(object):

Expand All @@ -72,15 +73,38 @@ class MetaSignal(type):
def __instancecheck__(object:object) -> bool: ...


class Property(object):
_PO = typing.TypeVar("_PO", bound="PySide2.QtCore.QObject")
_PT = typing.TypeVar("_PT")

def __init__(self, type:type, fget:typing.Optional[typing.Callable]=..., fset:typing.Optional[typing.Callable]=..., freset:typing.Optional[typing.Callable]=..., fdel:typing.Optional[typing.Callable]=..., doc:str=..., notify:typing.Optional[typing.Callable]=..., designable:bool=..., scriptable:bool=..., stored:bool=..., user:bool=..., constant:bool=..., final:bool=...) -> PySide2.QtCore.Property: ...
class Property(typing.Generic[_PO, _PT]):

def deleter(self, func:typing.Callable) -> None: ...
def getter(self, func:typing.Callable) -> None: ...
def read(self, func:typing.Callable) -> None: ...
def setter(self, func:typing.Callable) -> None: ...
def write(self, func:typing.Callable) -> None: ...
def __init__(self, type:typing.Type[_PT], fget:typing.Optional[typing.Callable[[_PO], _PT]]=..., fset:typing.Optional[typing.Callable[[_PO, _PT], None]]=..., freset:typing.Optional[typing.Callable[[_PO], None]]=..., fdel:typing.Optional[typing.Callable[[_PO], None]]=..., doc:str=..., notify:typing.Optional[PySide2.QtCore.Signal]=..., designable:bool=..., scriptable:bool=..., stored:bool=..., user:bool=..., constant:bool=..., final:bool=...) -> PySide2.QtCore.Property[_PT]: ...

fget: typing.Optional[typing.Callable[[_PO], _PT]]
fset: typing.Optional[typing.Callable[[_PO, _PT], None]]
freset: typing.Optional[typing.Callable[[_PO], None]]
fdel: typing.Optional[typing.Callable[[_PO], None]]

def getter(self, func:typing.Callable[[_PO], _PT]) -> PySide2.QtCore.Property[_PT]: ...
def setter(self, func:typing.Callable[[_PO, _PT], None]) -> PySide2.QtCore.Property[_PT]: ...
def deleter(self, func:typing.Callable[[_PO], None]) -> PySide2.QtCore.Property[_PT]: ...

# aliases for getter and setter
def read(self, func:typing.Callable[[_PO], _PT]) -> PySide2.QtCore.Property[_PT]: ...
def write(self, func:typing.Callable[[_PO, _PT], None]) -> PySide2.QtCore.Property[_PT]: ...

# HACK - Property is not actually a descriptor and does not define these methods;
# it's QObject's __getattribute__ which is responsible for resolving properties,
# but there's no way for us to type hint that. attempting to access these methods directly
# at runtime will cause an error
@typing.overload
def __get__(self, instance: None, owner: typing.Optional[typing.Type[typing.Any]] = ...) -> Property[_PT]:
...
@typing.overload
def __get__(self, instance: _PO, owner: typing.Optional[typing.Type[_PO]] = ...) -> _PT:
...
def __set__(self, instance: _PO, value: _PT) -> None:
...


class QAbstractAnimation(PySide2.QtCore.QObject):
Expand Down Expand Up @@ -13565,17 +13589,17 @@ class Qt(Shiboken.Object):
class WindowFlags(object):

def __index__(self) -> int: ...
def __init__(self, value: typing.Union[int, WindowType, WindowFlags] = ...) -> None: ...
def __or__(self, other: typing.Union[int, WindowType, WindowFlags]) -> WindowFlags: ...
def __and__(self, other: typing.Union[int, WindowType, WindowFlags]) -> WindowFlags: ...
def __xor__(self, other: typing.Union[int, WindowType, WindowFlags]) -> WindowFlags: ...
def __ror__(self, other: typing.Union[int, WindowType, WindowFlags]) -> WindowFlags: ...
def __rand__(self, other: typing.Union[int, WindowType, WindowFlags]) -> WindowFlags: ...
def __rxor__(self, other: typing.Union[int, WindowType, WindowFlags]) -> WindowFlags: ...
def __ior__(self, other: typing.Union[int, WindowType, WindowFlags]) -> WindowFlags: ...
def __iand__(self, other: typing.Union[int, WindowType, WindowFlags]) -> WindowFlags: ...
def __ixor__(self, other: typing.Union[int, WindowType, WindowFlags]) -> WindowFlags: ...
def __invert__(self) -> WindowFlags: ...
def __init__(self, value: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags] = ...) -> None: ...
def __or__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __and__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __xor__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __ror__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __rand__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __rxor__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __ior__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __iand__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __ixor__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType, PySide2.QtCore.Qt.WindowFlags]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __invert__(self) -> PySide2.QtCore.Qt.WindowFlags: ...

class WindowFrameSection(object):
NoSection : Qt.WindowFrameSection = ... # 0x0
Expand Down Expand Up @@ -13630,57 +13654,57 @@ class Qt(Shiboken.Object):
def __invert__(self) -> WindowStates: ...

class WindowType(object):
WindowFullscreenButtonHint: Qt.WindowType = ... # -0x80000000
Widget : Qt.WindowType = ... # 0x0
Window : Qt.WindowType = ... # 0x1
Dialog : Qt.WindowType = ... # 0x3
Sheet : Qt.WindowType = ... # 0x5
Drawer : Qt.WindowType = ... # 0x7
Popup : Qt.WindowType = ... # 0x9
Tool : Qt.WindowType = ... # 0xb
ToolTip : Qt.WindowType = ... # 0xd
SplashScreen : Qt.WindowType = ... # 0xf
Desktop : Qt.WindowType = ... # 0x11
SubWindow : Qt.WindowType = ... # 0x12
ForeignWindow : Qt.WindowType = ... # 0x21
CoverWindow : Qt.WindowType = ... # 0x41
WindowType_Mask : Qt.WindowType = ... # 0xff
MSWindowsFixedSizeDialogHint: Qt.WindowType = ... # 0x100
MSWindowsOwnDC : Qt.WindowType = ... # 0x200
BypassWindowManagerHint : Qt.WindowType = ... # 0x400
X11BypassWindowManagerHint: Qt.WindowType = ... # 0x400
FramelessWindowHint : Qt.WindowType = ... # 0x800
WindowTitleHint : Qt.WindowType = ... # 0x1000
WindowSystemMenuHint : Qt.WindowType = ... # 0x2000
WindowMinimizeButtonHint : Qt.WindowType = ... # 0x4000
WindowMaximizeButtonHint : Qt.WindowType = ... # 0x8000
WindowMinMaxButtonsHint : Qt.WindowType = ... # 0xc000
WindowContextHelpButtonHint: Qt.WindowType = ... # 0x10000
WindowShadeButtonHint : Qt.WindowType = ... # 0x20000
WindowStaysOnTopHint : Qt.WindowType = ... # 0x40000
WindowTransparentForInput: Qt.WindowType = ... # 0x80000
WindowOverridesSystemGestures: Qt.WindowType = ... # 0x100000
WindowDoesNotAcceptFocus : Qt.WindowType = ... # 0x200000
MaximizeUsingFullscreenGeometryHint: Qt.WindowType = ... # 0x400000
CustomizeWindowHint : Qt.WindowType = ... # 0x2000000
WindowStaysOnBottomHint : Qt.WindowType = ... # 0x4000000
WindowCloseButtonHint : Qt.WindowType = ... # 0x8000000
MacWindowToolBarButtonHint: Qt.WindowType = ... # 0x10000000
BypassGraphicsProxyWidget: Qt.WindowType = ... # 0x20000000
NoDropShadowWindowHint : Qt.WindowType = ... # 0x40000000
WindowFullscreenButtonHint: PySide2.QtCore.Qt.WindowType = ... # -0x80000000
Widget : PySide2.QtCore.Qt.WindowType = ... # 0x0
Window : PySide2.QtCore.Qt.WindowType = ... # 0x1
Dialog : PySide2.QtCore.Qt.WindowType = ... # 0x3
Sheet : PySide2.QtCore.Qt.WindowType = ... # 0x5
Drawer : PySide2.QtCore.Qt.WindowType = ... # 0x7
Popup : PySide2.QtCore.Qt.WindowType = ... # 0x9
Tool : PySide2.QtCore.Qt.WindowType = ... # 0xb
ToolTip : PySide2.QtCore.Qt.WindowType = ... # 0xd
SplashScreen : PySide2.QtCore.Qt.WindowType = ... # 0xf
Desktop : PySide2.QtCore.Qt.WindowType = ... # 0x11
SubWindow : PySide2.QtCore.Qt.WindowType = ... # 0x12
ForeignWindow : PySide2.QtCore.Qt.WindowType = ... # 0x21
CoverWindow : PySide2.QtCore.Qt.WindowType = ... # 0x41
WindowType_Mask : PySide2.QtCore.Qt.WindowType = ... # 0xff
MSWindowsFixedSizeDialogHint: PySide2.QtCore.Qt.WindowType = ... # 0x100
MSWindowsOwnDC : PySide2.QtCore.Qt.WindowType = ... # 0x200
BypassWindowManagerHint : PySide2.QtCore.Qt.WindowType = ... # 0x400
X11BypassWindowManagerHint: PySide2.QtCore.Qt.WindowType = ... # 0x400
FramelessWindowHint : PySide2.QtCore.Qt.WindowType = ... # 0x800
WindowTitleHint : PySide2.QtCore.Qt.WindowType = ... # 0x1000
WindowSystemMenuHint : PySide2.QtCore.Qt.WindowType = ... # 0x2000
WindowMinimizeButtonHint : PySide2.QtCore.Qt.WindowType = ... # 0x4000
WindowMaximizeButtonHint : PySide2.QtCore.Qt.WindowType = ... # 0x8000
WindowMinMaxButtonsHint : PySide2.QtCore.Qt.WindowType = ... # 0xc000
WindowContextHelpButtonHint: PySide2.QtCore.Qt.WindowType = ... # 0x10000
WindowShadeButtonHint : PySide2.QtCore.Qt.WindowType = ... # 0x20000
WindowStaysOnTopHint : PySide2.QtCore.Qt.WindowType = ... # 0x40000
WindowTransparentForInput: PySide2.QtCore.Qt.WindowType = ... # 0x80000
WindowOverridesSystemGestures: PySide2.QtCore.Qt.WindowType = ... # 0x100000
WindowDoesNotAcceptFocus : PySide2.QtCore.Qt.WindowType = ... # 0x200000
MaximizeUsingFullscreenGeometryHint: PySide2.QtCore.Qt.WindowType = ... # 0x400000
CustomizeWindowHint : PySide2.QtCore.Qt.WindowType = ... # 0x2000000
WindowStaysOnBottomHint : PySide2.QtCore.Qt.WindowType = ... # 0x4000000
WindowCloseButtonHint : PySide2.QtCore.Qt.WindowType = ... # 0x8000000
MacWindowToolBarButtonHint: PySide2.QtCore.Qt.WindowType = ... # 0x10000000
BypassGraphicsProxyWidget: PySide2.QtCore.Qt.WindowType = ... # 0x20000000
NoDropShadowWindowHint : PySide2.QtCore.Qt.WindowType = ... # 0x40000000

def __index__(self) -> int: ...
def __init__(self, value: typing.Union[int, WindowType] = ...) -> None: ...
def __or__(self, other: typing.Union[int, WindowType]) -> WindowFlags: ...
def __and__(self, other: typing.Union[int, WindowType]) -> WindowFlags: ...
def __xor__(self, other: typing.Union[int, WindowType]) -> WindowFlags: ...
def __ror__(self, other: typing.Union[int, WindowType]) -> WindowFlags: ...
def __rand__(self, other: typing.Union[int, WindowType]) -> WindowFlags: ...
def __rxor__(self, other: typing.Union[int, WindowType]) -> WindowFlags: ...
def __ior__(self, other: typing.Union[int, WindowType]) -> WindowFlags: ...
def __iand__(self, other: typing.Union[int, WindowType]) -> WindowFlags: ...
def __ixor__(self, other: typing.Union[int, WindowType]) -> WindowFlags: ...
def __invert__(self) -> WindowFlags: ...
def __init__(self, value: typing.Union[int, PySide2.QtCore.Qt.WindowType] = ...) -> None: ...
def __or__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __and__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __xor__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __ror__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __rand__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __rxor__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __ior__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __iand__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __ixor__(self, other: typing.Union[int, PySide2.QtCore.Qt.WindowType]) -> PySide2.QtCore.Qt.WindowFlags: ...
def __invert__(self) -> PySide2.QtCore.Qt.WindowFlags: ...
@staticmethod
def bin(s:PySide2.QtCore.QTextStream) -> PySide2.QtCore.QTextStream: ...
@staticmethod
Expand Down Expand Up @@ -13843,10 +13867,12 @@ def Slot(*some_types: typing.Type, result: typing.Type = ...) \
typing.Callable[..., RetT]]: ...


_ET = typing.TypeVar("_ET", bound="enum.Enum")
_FT = typing.TypeVar("_FT", bound="enum.Flag")

def QEnum(arg__1:object) -> object: ...
def QEnum(arg__1: typing.Type[_ET]) -> typing.Type[_ET]: ...

def QFlag(arg__1:object) -> object: ...
def QFlag(arg__1: typing.Type[_FT]) -> typing.Type[_FT]: ...

def QT_TRANSLATE_NOOP(arg__1:object, arg__2:object) -> object: ...

Expand Down
Loading