Repository navigation
fix: Raise DefinitionError for a verb decorator without parentheses - #194
Merged
Merged
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
A verb decorator without its parentheses, such as
@method.getfor@method.get(), now raisesDefinitionErrorwhen the class is defined: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.getas a second spelling and decided against it: one way to write an endpoint. Supporting it would have needed three more overloads onMethod.__call__, and the type errors for ordinary calls would have got worse.Details
Method.__call__passespaththrough_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).pathis annotatedstr | Callable[..., object], which is what it can actually receive. The public overloads still saystr, so type checkers keep rejecting the bare form.@method.get(5), already raised aTypeErrorat class creation and is unchanged.Fixedentry.Testing
test_a_verb_without_parentheses_raises_when_it_is_decoratedintest/test_endpoints.py.make checkpasses: lint, pyright and mypy, and 379 tests at 99% coverage.🤖 Generated with Claude Code