Skip to content

fix: Raise DefinitionError for a verb decorator without parentheses - #194

Merged
slatecipher merged 1 commit into
mainlinefrom
fix/verb-without-parentheses
Nov 29, 2026
Merged

slatecipher merged 1 commit into
mainlinefrom
fix/verb-without-parentheses

Conversation

@slatecipher

Copy link
Copy Markdown
Owner

What changed

A verb decorator without its parentheses, such as @method.get for @method.get(), now raises DefinitionError when the class is defined:

DefinitionError: Endpoint 'Api.ping': write `@method.get()`, with parentheses, even for an endpoint with no path.

Why

Before this change, the bare form defined the class without complaint, and the first call failed with TypeError: Api(base_url=..., user_agent=...) is not a callable object, which doesn't point at the decorator. That breaks the rule that a mistake in an endpoint fails when its module is imported. Pyright and mypy already rejected it, but only for people who run a type checker.

We discussed supporting @method.get as a second spelling and decided against it: one way to write an endpoint. Supporting it would have needed three more overloads on Method.__call__, and the type errors for ordinary calls would have got worse.

Details

  • Method.__call__ passes path through _checked_path, which raises if it's a callable. The check lives in a helper because adding it to __call__ took it past ruff's complexity limit (C901).
  • The implementation's path is annotated str | Callable[..., object], which is what it can actually receive. The public overloads still say str, so type checkers keep rejecting the bare form.
  • A non-string path that isn't callable, such as @method.get(5), already raised a TypeError at class creation and is unchanged.
  • The endpoints guide and llms.txt now say the parentheses are required. CHANGELOG has a Fixed entry.

Testing

  • New test_a_verb_without_parentheses_raises_when_it_is_decorated in test/test_endpoints.py.
  • make check passes: lint, pyright and mypy, and 379 tests at 99% coverage.

🤖 Generated with Claude Code

- Raise `DefinitionError` when a verb decorates a method directly, such as
  `@method.get` for `@method.get()`, naming the endpoint and the fix.
- It used to define the class anyway and fail at the first call with a
  `TypeError` that didn't point at the decorator.
- Say in the endpoints guide and llms.txt that the parentheses are required.
- Type checkers already rejected the bare form; its public signature is
  unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@slatecipher slatecipher added the bug Something isn't working label Nov 29, 2026
@slatecipher slatecipher self-assigned this Nov 29, 2026
@slatecipher
slatecipher merged commit fc801c6 into mainline Nov 29, 2026
8 checks passed
@slatecipher
slatecipher deleted the fix/verb-without-parentheses branch November 29, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant