• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aio-libs / multidict / 34026791742
87%

Build:
DEFAULT BRANCH: master
Ran 06 Sep 2026 10:13AM UTC
Jobs 1
Files 31
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

06 Sep 2026 10:12AM UTC coverage: 85.267% (+0.03%) from 85.241%
34026791742

push

github

web-flow
Use repr() to escape keys in MultiDict __repr__ output (#1342)

## What do these changes do?

Make `repr(MultiDict(...))` produce a parseable string when keys contain
quote characters. The pure-Python and C-extension code paths previously
wrapped keys in literal single quotes, so a key like `a'b` produced the
broken output `<MultiDict('a'b': 1)>`. They now format keys via Python's
`repr()`, which picks valid quoting automatically.

Before:

```python
>>> repr(MultiDict([("a'b", 1)]))
"<MultiDict('a'b': 1)>"        # not valid Python
```

After:

```python
>>> repr(MultiDict([("a'b", 1)]))
'<MultiDict("a\'b": 1)>'       # valid string literal
```

## Are there changes in behavior for the user?

Only for keys containing characters that need escaping in a Python
string literal (single quotes, control characters, …). Such repr output
was already broken, so any consumer was either tolerating bad output or
already wrapping keys themselves. Plain-ASCII keys produce
byte-identical
output, so the existing repr tests continue to pass unchanged.

## How

- **Pure-Python** (`multidict/_multidict_py.py`): four `f"'{key}'"` /
`f"'{key}': {v!r}"` patterns in `_ItemsView.__repr__`,
`_KeysView.__repr__`,
`MultiDict.__repr__`, and `MultiDictProxy.__repr__` switched to
`{key!r}`.
- **C extension** (`multidict/_multilib/hashtable.h`): the three-step
  *write `'`, write str, write `'`* sequence in `md_repr` is replaced by
  a single `PyUnicodeWriter_WriteRepr(writer, key)`. All views
  (`MultiDict`, proxies, keys/items views) delegate to this function, so
  one fix covers them all.

## Testing

- Three new tests in `tests/test_multidict.py::BaseMultiDictTest`
  (parametrized over `MultiDict`/`CIMultiDict` and both implementations)
  assert the repr of a multidict with a quoted key, plus its keys and
  items views, is the expected escaped form.
- Full local suite: `1682 passed` (was 1658 before, +24 from the new
  parametrized tests) on Python 3.12, C-ext + pure-Python.
- ... (continued)

627 of 1254 branches covered (50.0%)

Branch coverage included in aggregate %.

14 of 14 new or added lines in 2 files covered. (100.0%)

4171 of 4373 relevant lines covered (95.38%)

1.91 hits per line

Jobs
ID Job ID Ran Files Coverage
1 MyPy - 34026791742.1 06 Sep 2026 10:13AM UTC 62
85.27
GitHub Action Run
Source Files on build 34026791742
  • Tree
  • List 31
  • Changed 3
  • Source Changed 2
  • Coverage Changed 2
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Repo
  • Github Actions Build #34026791742
  • bee34455 on github
  • Prev Build on master (#34026452283)
  • Next Build on master (#34027710443)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc