Repository navigation
fix(utilities): fall back to the default threading excepthook before Python 3.10 (#1691) - #1701
Conversation
|
Verdict: GOOD TO GO at |
|
Coverage: 89.47% (unit tier, Python 3.15,
Per-file detail: the |
|
I'd actually prefer if possible, use |
|
Recorded: the default-hook detection and its fallback move into |
…Python 3.10 (#1691) `threading.__excepthook__` is 3.10+, so `_threading_excepthook`'s re-entry fallback and its no-previous-hook delegate raised `AttributeError` on 3.8 and 3.9. - `pcapkit.utilities.compat` re-exports the default as `default_threading_excepthook`, chosen by `sys.version_info`: `threading.__excepthook__` from 3.10, `_thread._excepthook` on 3.8 and 3.9 (the same object), `None` below 3.8. `exceptions.py` imports it and keeps no feature probe of its own. - Tests capture the default before `import pcapkit` instead of reading `threading.__excepthook__`, and cover both fallbacks in-process and a hook installed before import. `test_compat` covers each branch of the new name, faking 3.5 and 3.9 through a generalised `load_compat_as`. The touched modules pass on 3.8.20, 3.9.25, 3.10.21 and 3.14.8.
9c68294 to
a8d248e
Compare
|
Verdict: GOOD TO GO at
|
Please follow the guide below
You will be asked some questions, please read them carefully and answer honestly
Put an
xinto all the boxes [ ] relevant to your pull request (like that [x])Use Preview tab to see how your pull request will actually look like
Searched for similar pull requests
Followed the coding style (
make pylint,make mypy,make isort). Run on the two touched library files with the Makefile flags. isort is clean. pylint (3 messages) and mypy (1) report only lines ofcompat.pythis PR does not touch, andmainreports the same ones.make testpasses, and a test case covers the change. Not ticked because the whole suite was not run. The touched module's tests pass and cover the change.Added a changelog entry under
docs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible: N/A — centralised in docs(changelog): shared 1.5.0 changelog — long-lived, merges last (#610, #616, #617, #618, #620) #657What is the purpose of your pull request?
Tick the commit type your subject line carries.
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything elseDescription of your pull request and other information
threading.__excepthook__only exists from Python 3.10. Both fallbacks in_threading_excepthooktherefore raisedAttributeErroron 3.8 and 3.9: the re-entry fallback and the delegate used when no previous hook was saved.pcapkit.utilities.compatre-exports the default hook asdefault_threading_excepthook. It is chosen bysys.version_info:threading.__excepthook__on 3.10+,_thread._excepthookon 3.8 and 3.9, andNonebelow 3.8. Before 3.10, CPython startsthreading.excepthookas_thread._excepthook, and 3.10+ binds that same object as__excepthook__; I checked both withis. So the default is right even when a host hook was installed before import.exceptions.pyimports the name and no longer probes withgetattr. The name is not the stdlib__excepthook__, because imported into a module that reads assys.__excepthook__, which takes three arguments. The utilities docs' compatibility table gets a row.DEFAULT_THREADING_HOOKbehind a version gate, beforeimport pcapkit. Four new tests there cover the no-previous-hook delegate, the re-entry fallback, and a hook installed before import.test_compatadds three checks. A fresh interpreter confirms the name is its startup hook, even after a host hook replaced it. The 3.5 fake assertsNone. A new 3.9 fake confirms that on 3.10+ the_threadroute givesthreading.__excepthook__. To allow that,load_compat_as_python35becomesload_compat_as(name, version), andWARM_BEFORE_FAKINGgains_thread,builtinsandfunctools.Results. On
main, the 4 tests named in #1691 fail on 3.8.20 and 3.9.25. With the fix, the 28 tests oftest_compatandtest_exceptions_excepthookpass on 3.8.20, 3.9.25, 3.10.21 and 3.14.8, under both unittest and pytest. 14 more modules that touchcompator these hooks pass on all four as well. Each newcompattest fails against a mutant of one branch. On 3.14,compat.pystays at 100% coverage andexceptions.pygoes from 77% to 85%.Closes #1691