-
-
Notifications
You must be signed in to change notification settings - Fork 99
Fix Python 3.14 compatiblity #780
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
base: main
Are you sure you want to change the base?
Fix Python 3.14 compatiblity #780
Conversation
Python 3.14 changed IOBase error message from 'Exception ignored in.' to 'Exception ignored while calling deallocator', breaking the existing regex filter. Updated to match both formats. Also reverted .pre-commit-config.yaml to python3.14 (CI doesn't have 3.13).
β¦ config - Only force 'fork' on Unix (Windows doesn't support fork method) - Change flake8 language_version to python3.11 for CI compatibility - Fixes ValueError on Windows: 'cannot find context for fork'
- Replace try-except-pass with contextlib.suppress (ruff SIM105) - Shorten comment lines to meet 79 char limit (flake8 LN002) - Split nested try blocks to satisfy flake8 WPS229 - Remove unused WPS436 noqa comment
- flake8-spellcheck ~= 0.28.0 | ||
- wemake-python-styleguide ~= 1.1.0 | ||
language_version: python3.11 # flake8-commas doesn't work w/ Python 3.12 | ||
# Use Python 3.11 for CI compatibility (flake8-annotations not 3.14 ready) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just update the existing comment. Disconnected comments tend to get lost. Also, it's obvious that Python 3.11 is used from YAML. No need to repeat things too verbosely for the sake of verboseness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides, only the old version is not compatible with Python 3.12. It's unknown if a newer isn't compatible with 3.14. But since there's a release with 3.13 in Trove classifiers, it would make sense to bump the dependency version and maybe bump this to 3.13 if that work + verify if 3.14 could work too.
# Python 3.14 compatibility: Force 'fork' multiprocessing on Unix | ||
# Python 3.14 changed default from 'fork' to 'forkserver' on Unix, | ||
# which can cause issues with pytest-xdist's parallel test execution. | ||
# This ensures compatibility with existing test fixtures and shared state. | ||
# Note: Windows doesn't support 'fork', so we skip this on Windows. | ||
# Ref: https://github.com/cherrypy/cheroot/issues/767 | ||
if sys.version_info >= (3, 14) and not IS_WINDOWS: | ||
with contextlib.suppress(ImportError): | ||
import multiprocessing | ||
|
||
with contextlib.suppress(RuntimeError): | ||
# Force fork method even if already set to forkserver | ||
multiprocessing.set_start_method('fork', force=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem to have any proof of the justification. Show me fact-checking and actual research. Unnamed possible issues is too broad to make sense of it. Also, post the actual CI failure log (with a link to the line in the log) that this is supposedly addressing.
import pytest | ||
|
||
from .._compat import IS_MACOS, IS_WINDOWS # noqa: WPS436 | ||
from .._compat import IS_MACOS, IS_WINDOWS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is unrelated and can be submitted separately.
# Python 3.14: PEP 765 - control flow statements in finally blocks | ||
# Added as defensive measure even though current code has no violations | ||
# Ref: https://github.com/cherrypy/cheroot/issues/767 | ||
ignore::SyntaxWarning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must not be ignored. Definitely not as a blanket suppression without justification.
# Python 3.14 changed error message format from "Exception ignored in." to | ||
# "Exception ignored while calling deallocator", so we use a regex that matches both | ||
ignore:Exception ignored.*IOBase.__del__:pytest.PytestUnraisableExceptionWarning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, this should be fixed. But since there was a suppression in place already, It's fine to keep it for now.
# Python 3.14: Free-threaded build context-aware warnings | ||
# Context-aware warnings may behave differently in free-threaded builds | ||
# Ref: https://github.com/cherrypy/cheroot/issues/767 | ||
ignore:.*context.*:RuntimeWarning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't have any specifics and therefore is not a good/acceptable justification.
β What kind of change does this PR introduce?
π What is the related issue number (starting with
#
)Resolves #767
β What is the current behavior? (You can also link to an open issue here)
Python 3.14 tests fail in CI with:
fork
toforkserver
on Unixβ What is the new behavior (if this is a feature change)?
All tests pass on Python 3.14 (Linux and Windows) with full backward compatibility for Python 3.8-3.13.
π Other information:
Root Cause: Python 3.14 changed the default multiprocessing start method from
fork
toforkserver
on Unix platforms, breaking pytest-xdist parallel test execution.Solution Applied:
Multiprocessing Fix (
cheroot/test/conftest.py
):fork
method on Python 3.14+ Unix systems onlycontextlib.suppress
IOBase Warning Filter (
pytest.ini
):"Exception ignored in."
to"Exception ignored.*"
Pre-commit Config (
.pre-commit-config.yaml
):language_version: python3.11
to match CITesting: Verified on Python 3.14.0rc3 with pytest-xdist parallel execution (n=auto).
π Contribution checklist:
the changes have been approved
and description in grammatically correct, complete sentences
This change isβ