Skip to content

Look up params, attrs and raises by name - #197

Merged
rr- merged 1 commit into
mainfrom
rework/89-lookup-by-name
Nov 7, 2026
Merged

rr- merged 1 commit into
mainfrom
rework/89-lookup-by-name

Conversation

@rr-

@rr- rr- commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Add read-only lookups by name next to the lists they mirror, as asked in #89: Docstring.params_by_name, attrs_by_name and raises_by_type.

  • Each is a Mapping[str, ...] property: a types.MappingProxyType over a dict built from meta on every access. Nothing is cached, so a lookup always matches meta, and both the type checker and the runtime reject writes to it.
  • A name given twice maps to its first item, the same way returns takes the first return. The lists keep every item. For raises this means two conditions that raise ValueError give the first one; raises still has both. Raises with no type are left out.
  • raises_by_type covers what raises lists, so warns are in it too.
  • No methods_by_name: a method's name is its signature as written, such as run(x, y=1), so a lookup by it would rarely be useful.
  • Tests in test_kinds.py cover each style, a repeated name, raises with and without a type, and that a lookup is read-only and follows changes to meta.
  • Parity against main: none of 29184 docstrings differ. Bench: worst ratio 1.02 on Python 3.8 and on 3.14.

Closes #89.

Add Docstring.params_by_name, attrs_by_name and raises_by_type next to
the lists they mirror. Each is a read-only Mapping built from meta on
every access, so it can't go stale, and a name given twice maps to its
first item, as returns takes the first return. Raises with no type are
left out.

Closes #89.
@rr- rr- self-assigned this Nov 7, 2026
@rr-
rr- merged commit a8e2a3b into main Nov 7, 2026
26 checks passed
@rr-
rr- deleted the rework/89-lookup-by-name branch November 7, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change Docstring.params (and others) to be dict-like types

1 participant