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

mypy==0.991 #202

Open
wants to merge 10 commits into
base: master
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
14 changes: 13 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ def find_version(*file_paths):
package_data={"PyQt5-stubs": ['*.pyi']},
packages=["PyQt5-stubs"],
extras_require={
"dev": ["mypy==0.930", "pytest", "pytest-xvfb"],
"dev": [
# 0.940 introduced class finality testing that segfaults on PyQt5
# https://github.com/python/mypy/commit/080bb0e04e9d5c4d2513621d1fb62f1d61a573e9
# https://www.riverbankcomputing.com/pipermail/pyqt/2022-November/045068.html
# >= 0.990 for monkey patchable class finality check function
# https://github.com/python/mypy/commit/55d757e4910a0ae73175a71f3c0f02caad53e059
"mypy==0.991; python_version >= '3.7'",
# 0.981 dropped 3.6 support
# https://github.com/python/mypy/commit/dc118e293203863ab1007699b2cecf0f26ddfa22
"mypy<0.940; python_version < '3.7'",
"pytest",
"pytest-xvfb",
],
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know you can do things like this. Nice!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the env_var list at https://peps.python.org/pep-0508/.

env_var       = ('python_version' | 'python_full_version' |
                 'os_name' | 'sys_platform' | 'platform_release' |
                 'platform_system' | 'platform_version' |
                 'platform_machine' | 'platform_python_implementation' |
                 'implementation_name' | 'implementation_version' |
                 'extra' # ONLY when defined by a containing layer
                 )

Though it appears this boundary may belong closer to 0.981 python/mypy@dc118e2.

classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
44 changes: 44 additions & 0 deletions stubtest_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# workaround for https://github.com/python/mypy/issues/14196

import faulthandler
import sys
import typing

import mypy.stubtest


sentinel = object


def noop_generator(*args, **kwargs) -> typing.Iterator[object]:
return
yield # make it a generator as the original is


def maybe_monkey_patch(object_: object, name: str, replacement: object) -> None:
attribute = getattr(object_, name, sentinel)
if attribute is sentinel:
print(f"{name} does not exist on {object_}, skipping monkey patching")
return

setattr(object_, name, replacement)
print(f"{name} on {object_} monkey patched by {replacement}")
return


def main() -> int:
maybe_monkey_patch(
object_=mypy.stubtest,
name="_verify_final",
replacement=noop_generator,
)

# make sure the messages get out since we're working around a segfault here
sys.stdout.flush()
# in case we still get a segfault, try to report it
faulthandler.enable()

return mypy.stubtest.main()


sys.exit(main())
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ commands =
pip install 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
pip freeze --all
mypy --show-error-codes -p PyQt5-stubs
stubtest --allowlist {toxinidir}/{env:ALLOWLIST} --allowlist {toxinidir}/stubtest.allowlist.to_review --allowlist {toxinidir}/stubtest.allowlist.{env:OS_MARKER} PyQt5
python {toxinidir}/stubtest_wrapper.py --allowlist {toxinidir}/{env:ALLOWLIST} --allowlist {toxinidir}/stubtest.allowlist.to_review --allowlist {toxinidir}/stubtest.allowlist.{env:OS_MARKER} PyQt5
pytest --capture=no --verbose {posargs}

[pytest]
addopts = --strict-markers
testpaths = tests
xfail_strict = true