Skip to content

Document the --no-c-extensions flag for the pure-Python test run - #1523

Merged
asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:document-no-c-extensions-flag
Sep 22, 2026
Merged

asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:document-no-c-extensions-flag

Conversation

@asvetlov

Copy link
Copy Markdown
Member

What do these changes do?

The pure-Python test command in AGENTS.md did not actually run the
pure-Python suite. MULTIDICT_NO_EXTENSIONS=1 selects the backend that
import multidict resolves to, but it has no effect on test selection:
the C-extension half of the matrix in tests/conftest.py carries a
c_extension marker, and only --no-c-extensions deselects it. Those
tests import multidict._multidict directly, so following the
documented command either errored out with ModuleNotFoundError when
no extension had been built, or silently ran against a stale .so left
in the tree by an earlier C-extension install.

The command now passes both, with a short paragraph on why each is
needed. Documentation only; no code or test changes.

Are there changes in behavior for the user?

No.

Is it a substantial burden for the maintainers to support this?

No.

Related issue number

None.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist — N/A, documentation-only change
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt — N/A, no such file in this repo
  • Add a new news fragment into the CHANGES/ folder
  • make doc-spelling passes and any new technical words are added to docs/spelling_wordlist.txt

Drafted with Claude Code (Opus 5); reviewed by @asvetlov.

Agent run details (optional, for reviewers)

Both failure modes reproduced before the change, on CPython 3.14.7t.

Clean checkout, no .so present, running the command exactly as
AGENTS.md documented it:

$ MULTIDICT_NO_EXTENSIONS=1 pip install -e . --force-reinstall --no-deps
$ MULTIDICT_NO_EXTENSIONS=1 pytest tests -q
E   ModuleNotFoundError: No module named 'multidict._multidict'
ERROR tests/test_abc.py::test_multidict_inheritance[cs-c]
1 passed, 9 skipped, 1 error

Same tree with a .so left over from a previous C-extension install:
the [c] params and the standalone c_extension-marked tests collect
and run against the extension, which is the case that reports a
meaningless pass. 49 tests failed that way in the worktree this was
found in, because the .so was stale relative to the checked-out
source.

With the flag, on both trees:

$ MULTIDICT_NO_EXTENSIONS=1 pytest tests -q --no-c-extensions
1103 passed, 9 skipped, 1106 deselected      # clean tree, no .so
1104 passed, 1253 deselected                 # tree with a stale .so

Docs:

$ make doc-spelling
build succeeded.

pre-commit run over the changed files passes.

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Sep 22, 2026
Setting MULTIDICT_NO_EXTENSIONS=1 picks the backend that gets
imported, but it does not deselect the C-extension half of the test
matrix; only --no-c-extensions does. The c_extension-marked tests
import multidict._multidict directly, so the command as documented
errored out when no extension had been built, and silently tested a
stale .so when one was left in the tree.
@asvetlov
asvetlov force-pushed the document-no-c-extensions-flag branch from 7b8ea38 to 84170f5 Compare September 22, 2026 22:22
@codspeed

codspeed Bot commented Sep 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 298 untouched benchmarks


Comparing asvetlov:document-no-c-extensions-flag (84170f5) with master (1cdd934)

Open in CodSpeed

@asvetlov
asvetlov marked this pull request as ready for review September 22, 2026 22:40
@asvetlov
asvetlov requested a review from webknjaz as a code owner September 22, 2026 22:40
@greptile-apps

greptile-apps Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

Safe to merge; the updated instructions execute as documented and select the intended pure-Python test coverage.

What we checked:

  • Installed the project using the documented pure-Python editable install and confirmed that MULTIDICT_NO_EXTENSIONS=1 routes the public multidict.MultiDict API to the pure-Python implementation. T-Rex
  • Compared test collections with and without the --no-c-extensions flag and observed that C-extension variants were removed while Python variants remained. T-Rex
  • Ran a representative test module under the described environment and flag; 17 tests passed and 23 C-extension tests were deselected. T-Rex
  • Authored and executed the validate-pure-python-instructions script to capture end-to-end evidence, generating install, import, before/after selection, and runtime test logs. T-Rex

Reviews (1) · Last reviewed commit: "Document the --no-c-extensions flag for ..."

@asvetlov
asvetlov merged commit a794a6e into aio-libs:master Sep 22, 2026
61 checks passed
@asvetlov
asvetlov deleted the document-no-c-extensions-flag branch September 22, 2026 22:54
asvetlov added a commit that referenced this pull request Sep 23, 2026
<!-- Thank you for your contribution! -->

## What do these changes do?

`md_clear()` holds the last three stores to a shared entry field that do
not go through `_multilib/freethreading.h`. #1518 left them alone on
purpose but recorded the reason only in its own PR footer, so this puts
it
at the site. Nothing else changes.

Keeping the raw access wins on two counts. `Py_CLEAR()` is not a decref
plus `reset_identity()`: it skips the store entirely when the field is
already NULL, which the accessors cannot express. And the block is the
`#else` arm of `#ifdef Py_GIL_DISABLED`, so it compiles only on the GIL
build, where every accessor is plain field access and there is no
ordering
for one to carry; the free-threaded build reaches none of it, since
`_md_retire()` owns that path. A `clear_identity()` would therefore
exist
solely for a single GIL-only call site, which fails the bar #1518 set
for
adding an accessor: it has to unify the two builds.

The two alternatives were built and measured rather than argued about;
the
numbers are in the footer.

## Are there changes in behavior for the user?

No. Both builds compile to byte-identical machine code.

## Is it a substantial burden for the maintainers to support this?

No. It is four lines of comment.

## Related issue number

None. Split out of #1518, which reported these sites.

## Checklist

- [x] I think the code is well written
- [x] Unit tests for the changes exist (N/A, comment only; the existing
suite is the test)
- [x] Documentation reflects the changes (N/A, internal C header)
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt`
- [x] Add a new news fragment into the `CHANGES/` folder
- [x] `make doc-spelling` passes and any new technical words are added
to `docs/spelling_wordlist.txt`

Drafted with Claude Opus 5; reviewed by @asvetlov.

<details>
<summary>Agent run details (optional, for reviewers)</summary>

Codegen, `objdump -d --no-show-raw-insn` compared per function against
`master` at a794a6e with addresses, RIP displacements and intra-function
branch offsets normalised. The harness was checked two ways first: two
builds of the same tree are identical, and a throwaway comment inserted
at
the same spot is also identical, so it does not simply fail to notice
things.

| Variant | GIL build | Free-threaded build |
| --- | --- | --- |
| This PR (comment only) | 0 of 239 functions differ | 0 of 253 differ |
| `clear_identity()`/`clear_value()` accessors replicating `Py_CLEAR()`
exactly, including the skipped store | 23 of 239 differ | n/a,
unreachable there |
| Load, `reset_identity()`/`reset_value()`, then `Py_XDECREF` | 40 of
239 differ | n/a |

The accessor variant is worth a note: its inlined body is the same
instruction sequence, but GCC rotates the clearing loop differently, so
it
cannot be shown to be a no-op even though it is one. That is the whole
reason this PR does not take it.

Tests, all on this commit:

- GIL build, CPython 3.14.2, C extension: 2210 passed, 21 skipped.
- Free-threaded build, 3.14.7t, C extension: 2199 passed, 32 skipped.
- Pure Python, per the recipe #1523 just added: 1103 passed, 15 skipped,
1112 deselected.

No sanitizer or ThreadSanitizer run is quoted. The machine code is
unchanged, so there is nothing for them to say that CI's own legs do
not.

`make doc-spelling` passes. `pre-commit run` passes; clang-format leaves
the comment as written.

</details>
asvetlov added a commit that referenced this pull request Sep 23, 2026
<!-- Thank you for your contribution! -->

## What do these changes do?

`AGENTS.md` described how to run the suite without mentioning that the
property tests under `tests/test_hypothesis_*.py` are not part of it.
`pytest.ini` sets `-m "not hypothesis"`, so a plain `make test` skips
them and reports a pass, and `make install-dev` does not install
hypothesis either, since the pin lives in its own
`requirements/pytest-hypothesis.txt`. Someone following the file as
written would believe they had run the whole suite.

The Tests section now records the marker override, the separate
requirements file and the reason it is separate, and the fact that one
`-m hypothesis` run already covers both backends. Documentation only.

## Are there changes in behavior for the user?

No.

## Is it a substantial burden for the maintainers to support this?

No.

## Related issue number

None. Follow-up to #1523, which fixed the pure-Python invocation in the
same section.

## Checklist

- [x] I think the code is well written
- [ ] Unit tests for the changes exist — N/A, documentation-only change
- [x] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt` — N/A, no such file in this repo
- [x] Add a new news fragment into the `CHANGES/` folder
- [x] `make doc-spelling` passes and any new technical words are added
to `docs/spelling_wordlist.txt`

Drafted with Claude Code (Opus 5); reviewed by @asvetlov.

<details>
<summary>Agent run details (optional, for reviewers)</summary>

Claims checked against the tree rather than assumed.

`make install-dev` really does not bring hypothesis in; a fresh venv
built from `requirements/dev.txt` has no `hypothesis` module:

```
$ pip install -r requirements/dev.txt && pip install -e .
$ python -c "import hypothesis"
ModuleNotFoundError: No module named 'hypothesis'
```

The documented commands, run verbatim on CPython 3.14.7t:

```
$ pip install -r requirements/pytest-hypothesis.txt
$ pytest -q -m hypothesis
143 passed, 4 skipped, 2210 deselected in 76.68s
```

That a single run covers both backends was confirmed by collection,
which yields `-c` and `-py` ids together:

```
$ pytest -m hypothesis --collect-only | grep -oE "\[(cs|ci)?-?(c|py)\]" | sort | uniq -c
      5 [c]
     27 [ci-c]
     27 [ci-py]
     27 [cs-c]
     27 [cs-py]
      5 [py]
```

The note on why the pin is kept out of `requirements/pytest.txt`, and
the two CI jobs, are taken from the existing comments on the
`hypothesis-gil` and `hypothesis-freethreading` jobs in
`.github/workflows/ci-cd.yml`.

```
$ make doc-spelling
build succeeded.
```

`pre-commit run` over the changed files passes.

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant