Repository navigation
fix(const): give the AppType registry dict union only where dict has it (#1694) - #1703
Conversation
|
Verdict: GOOD TO GO at |
|
Coverage: 89.47% (unit tier, Python 3.15,
Per-file detail: the |
|
prefer to use version gates, instead of |
…it (#1694) `_Registries.__or__`/`__ror__` called `dict.__or__`/`dict.__ror__` unconditionally. Dict union is PEP 584, Python 3.9 and up, so on 3.8 any `|` or `|=` with the registry first imported TCP and UDP and then raised `AttributeError`, where a plain dict raises `TypeError`. - Define both only `if sys.version_info >= (3, 9)`. Before 3.9 the registry now raises dict's `TypeError`, naming its own type, and imports nothing; from 3.9 nothing changes. `|=` stays dict's in-place update, which reads no value. `__dir__` leaves out the new `sys` import, as it does `importlib`. - Run the tests' `or`/`ror` views from 3.9 only, and pin which views ran. - Add `test_union_is_dict_s_on_every_python`: all four `|`/`|=` forms against dict's own behaviour on the running interpreter. Tests: the touched module passes on 3.8.20, 3.9.25, 3.10.21 and 3.14.8.
6be6781 to
1691825
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)make testpasses, and a test case covers the change. Only the touched module was run, on 3.8, 3.9, 3.10 and 3.14. The full suite is left to CI.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
_Registries.__or__/__ror__calleddict.__or__/dict.__ror__without a check. Dict union is new in 3.9 (PEP 584). On 3.8, any|or|=withAppType.__registries__imported TCP and UDP and then raisedAttributeError, where a plain dict raisesTypeError.if sys.version_info >= (3, 9), a version gate in the style ofpcapkit/utilities/compat.py.__dir__leaves out the newsysimport, as it already doesimportlib. On 3.8, all four forms (r | {},{} | r,r |= {},{} |= r) now raise dict'sTypeError, naming'_Registries', and import nothing. A 26-case probe of union forms (operator, dunder andhasattrcalls) gives the same output before and after on 3.9, 3.10 and 3.14.|=keeps dict's own in-place update, which reads no value, so the registry stays pending.or/rorviews run from 3.9 only, and an assertion pins which views ran. The newtest_union_is_dict_s_on_every_pythoncompares the four forms with dict's behaviour on the running interpreter.origin/mainunder 3.8.20, the two tests named in the issue fail withAttributeError(2 failed), and the new test errors in all four subtests. On 3.9.25,mainpasses 14 of 14.apptype/__init__.pyis 100% on 3.14. pylint, mypy and isort report nothing new.dict. The 3.10+keys().mappingreads go through the registry's own methods.Closes #1694