Skip to content

Add docstrings to FirstMatchRegistry - #832

Open
JazzyJJ0601 wants to merge 1 commit into
getsentry:masterfrom
JazzyJJ0601:docs/registry-docstrings
Open

JazzyJJ0601 wants to merge 1 commit into
getsentry:masterfrom
JazzyJJ0601:docs/registry-docstrings

Conversation

@JazzyJJ0601

Copy link
Copy Markdown

FirstMatchRegistry is the default registry, but unlike OrderedRegistry it had no docstrings. This adds them in the same numpy style: the class (including how multiple matches are handled), registered, reset, find, add (the deep copy when the same instance is added twice), remove and replace (both compare by method and URL, via BaseResponse.__eq__).

Docstrings only; no code changes. pytest responses/tests/test_registries.py passes.

AI disclosure: I found the gap with an audit tool I'm building, drafted the text with an AI assistant (Claude), and checked every line against the code by hand.

(Audit tool: Legacy Doc-AI.)

@JazzyJJ0601
JazzyJJ0601 requested a review from markstory as a code owner October 2, 2026 21:32

@mayureshsonawane17 mayureshsonawane17 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read through the proposed docstrings and compared them against the implementation in responses/registries.py.

The docstring formatting is clean and follows the project style. In FirstMatchRegistry.replace(), the docstring states it replaces the response with the same method and URL. Since self.registered.index(response) invokes BaseResponse.__eq__ (which evaluates matchers in addition to URL/method), would it be helpful to clarify that matcher equality is also considered?

Comment thread responses/registries.py

def replace(self, response: "BaseResponse") -> "BaseResponse":
"""Replace the registered response with the same method and URL as ``response``.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since self.registered.index(response) compares BaseResponse instances using __eq__ (evaluating matchers alongside method and URL), should the docstring note that matching rules/matchers are also evaluated when locating the response to replace?

Comment thread responses/registries.py
def add(self, response: "BaseResponse") -> "BaseResponse":
"""Register a response and return it.

If the same `Response` instance is already registered, a deep copy is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If the same `Response` instance is already registered, a deep copy is
If the same ``Response`` instance is already registered, a deep copy is

python docstrings are RST shaped.

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.

3 participants