Skip to content
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

SIGSEGV running stubtest against PyQt5-stubs with 0.940+ #14196

Closed
altendky opened this issue Nov 26, 2022 · 4 comments
Closed

SIGSEGV running stubtest against PyQt5-stubs with 0.940+ #14196

altendky opened this issue Nov 26, 2022 · 4 comments
Labels
bug mypy got something wrong topic-stubtest

Comments

@altendky
Copy link

Bug Report

When running stubtest for PyQt5-stubs we get a SIGSEGV. Bisecting PyPI published versions I see two boundaries. As of 0.940 the SIGSEGV began. As of 0.960 we started getting a few regular hint error messages prior to the SIGSEGV.

To Reproduce

I delete the venv first locally but hesitate to put recursive forced deletes where they could cause others damage.

python3.10 -m venv venv; venv/bin/pip install --upgrade pip; venv/bin/pip install . git+https://github.com/python/mypy@a9c62c5f82f34a923b8117a5394983aefce37b63 PyQt5==5.15.6 PyQt3D==5.15.5 PyQtChart==5.15.5 PyQtDataVisualization==5.15.5 PyQtNetworkAuth==5.15.5 PyQtPurchasing==5.15.5 PyQtWebEngine==5.15.5; venv/bin/stubtest --allowlist stubtest.allowlist --allowlist stubtest.allowlist.to_review --allowlist stubtest.allowlist.linux PyQt5

Expected Behavior

I expect stubtest to run without a SIGSEGV nor any other crash.

Actual Behavior

As mentioned above there are a few regular hint error messages starting with 0.960 but there's still a SIGSEGV.

error: PyQt5.Qt3DAnimation.PYQT_OPENGL_ARRAY is not present at runtime
Stub: at line 38 in file /home/altendky/repos/PyQt5-stubs/venv/lib/python3.10/site-packages/PyQt5-stubs/Qt3DAnimation.pyi
Type alias for Union[typing.Sequence[builtins.int], typing.Sequence[builtins.float], Union[builtins.bytes, builtins.bytearray, builtins.memoryview, PyQt5.sip.array[Any], PyQt5.sip.voidptr], None]
Runtime:
MISSING

error: PyQt5.Qt3DAnimation.PYQT_OPENGL_BOUND_ARRAY is not present at runtime
Stub: at line 40 in file /home/altendky/repos/PyQt5-stubs/venv/lib/python3.10/site-packages/PyQt5-stubs/Qt3DAnimation.pyi
Type alias for Union[typing.Sequence[builtins.int], typing.Sequence[builtins.float], Union[builtins.bytes, builtins.bytearray, builtins.memoryview, PyQt5.sip.array[Any], PyQt5.sip.voidptr], builtins.int, None]
Runtime:
MISSING

error: PyQt5.Qt3DAnimation.PYQT_SLOT is not present at runtime
Stub: at line 35 in file /home/altendky/repos/PyQt5-stubs/venv/lib/python3.10/site-packages/PyQt5-stubs/Qt3DAnimation.pyi
Type alias for Union[def (*Any, **Any), PyQt5.QtCore.pyqtBoundSignal]
Runtime:
MISSING

error: PyQt5.Qt3DAnimation.QAbstractAnimation is inconsistent, metaclass differs
Stub: at line 44 in file /home/altendky/repos/PyQt5-stubs/venv/lib/python3.10/site-packages/PyQt5-stubs/Qt3DAnimation.pyi
N/A
Runtime:
<class 'sip.wrappertype'>

fish: “venv/bin/stubtest --allowlist s…” terminated by signal SIGSEGV (Address boundary error)

Your Environment

  • Mypy version used: 0.960 through 0.991 and a9c62c5
  • Mypy command-line flags: stubtest --allowlist stubtest.allowlist --allowlist stubtest.allowlist.to_review --allowlist stubtest.allowlist.linux PyQt5
  • Mypy configuration options from mypy.ini (and other config files):
    https://github.com/python-qt-tools/PyQt5-stubs/blob/15fbb1ab6f23259fba7ceca3311e322fcf397000/setup.cfg
    [mypy]
    incremental = False
    
    strict = True
    warn_unreachable = True
    ignore_missing_imports = False
    
  • Python version used:
    locally tested with Python 3.10.8 (main, Oct 15 2022, 17:48:51) [GCC 9.4.0]
    observed in CI for 3.7 through 3.10
@altendky altendky added the bug mypy got something wrong label Nov 26, 2022
@altendky
Copy link
Author

Installing only PyQt5, without any of the auxiliary PyQt5 packages, results in more regular hint errors but still a SIGSEGV. Just in case that ends up being a preferable situation for debugging.

rm -rf venv; python3.10 -m venv venv; venv/bin/pip install --upgrade pip; venv/bin/pip install . mypy==0.991 PyQt5==5.15.6; venv/bin/stubtest --allowlist stubtest.allowlist --allowlist stubtest.allowlist.to_review --allowlist stubtest.allowlist.linux PyQt5

@hauntsaninja
Copy link
Collaborator

Weird, my usual guess for segfaults is mypyc, but it looks like there's some issue in PyQt5.

Specifically, a check was added to stubtest at some point to ensure final declarations on classes that could not be subclassed. Here's a minimal repro:

>>> import PyQt5.QtBluetooth
>>> class segfault(PyQt5.QtBluetooth.QBluetooth.AttAccessConstraint): ...
... 
Fatal Python error: Segmentation fault

Current thread 0x000000020295b600 (most recent call first):
  File "<stdin>", line 1 in <module>
zsh: segmentation fault  python3

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Nov 26, 2022

Here's an ad hoc stubtest patch that skips this check, in case it's useful for you:

diff --git a/mypy/stubtest.py b/mypy/stubtest.py
index 87ccbd317..0fcfa271b 100644
--- a/mypy/stubtest.py
+++ b/mypy/stubtest.py
@@ -352,6 +352,7 @@ def verify_mypyfile(
 def _verify_final(
     stub: nodes.TypeInfo, runtime: type[Any], object_path: list[str]
 ) -> Iterator[Error]:
+    return
     try:
 
         class SubClass(runtime):  # type: ignore[misc,valid-type]

I guess I could expose more stubtest configuration, but apart from that this seems like a PyQt5 thing.

@altendky
Copy link
Author

altendky commented Nov 28, 2022

Thanks for diagnosing this. I have reported upstream at https://www.riverbankcomputing.com/pipermail/pyqt/2022-November/045068.html though I don't know if it will get fixed as Qt5 is old and I don't know how much maintenance Phil is still doing on the PyQt5 series vs. working mostly on PyQt6.

I do tend to like configurability but I also understand that this does not seem to have caused any other issues so...

I'll look at making ourselves a small wrapper that monkey patches the _verify_final() function to be a no-op as you suggested. Thank you.

(edit: see wrapper at https://github.com/python-qt-tools/PyQt5-stubs/blob/7f86f099b8777b261df4197bec466045086fa6c3/stubtest_wrapper.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-stubtest
Projects
None yet
Development

No branches or pull requests

3 participants