Repository navigation
Routes live in client.routes; a route name cannot replace a client attribute (#23) - #24
Merged
Merged
Conversation
…nt attribute (#23) register_method did setattr(self, name, ...) with the spec's x-method_name, so a (possibly remote) spec could replace openapi_spec, session, handle_request... Every route now goes in client.routes; it is also set as an attribute only when its name is public and not already an attribute (a later route of the same name still replaces an earlier one). Otherwise a warning points to client.routes. api_pkg_maker and cli_maker enumerate client.routes, and generated packages call api.routes[name], so a route named like a client attribute still works there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- the CLI calls client.routes[name], not getattr (a route named like a client attribute ran the attribute) - title/version/base_url (never read after __init__) can still be route names, so existing clients and generated packages with such routes keep working - collisions are checked on the class and instance dict, not hasattr (a __getattr__ subclass refused every route); routes is created lazily for a subclass that skips HttpClient.__init__ - duplicate route names warn; warnings point at the caller (stacklevel=3); is_request_method looks at the attribute again Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Dependents gate ( |
This was referenced Oct 13, 2026
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.
Closes #23.
HttpClient.register_methoddidsetattr(self, name, ...)with the spec'sx-method_name, so a spec (possibly served by a remote) could replaceopenapi_spec,session,handle_request,ensure_login, ...Change
client.routes({name: bound method}).client.routes[name].title,version,base_url(set in__init__, never read afterwards) can still be taken by a route, so py2http services with a function namedversionkeep working, as do packages generated before this change.api_pkg_makerandcli_makerenumerateclient.routes; the CLI and generated packages callroutes[name], so a route named like a client attribute works there.Adversarial review (fresh Opus subagent): first verdict FIX-FIRST. Confirmed and fixed in the second commit: the CLI still dispatched by
getattr(a colliding route ran the client attribute);title/versionroutes would break existing generated packages and dependents usinggetattr(api, name)(now shadowable);hasattrrefused every route for a__getattr__subclass; a subclass skipping__init__had noroutes; warnings pointed into http2py (stacklevel);is_request_methoddisagreed with attribute access; silent duplicate-name loss. Not changed: no version floor added to generated packages'install_requires(a package generated by this version against an older http2py fails on import; generation and runtime normally share a version). Checked safe:{func_name!r}in the generated source (names are validated identifiers first).Tests:
tests/test_route_namespace.py(fail on master). Dependents gate: see comment.🤖 Generated with Claude Code