Repository navigation
Conversation
FastAPI and Flask apps often register handlers inside a factory, so
every handler's decisions were charged to the factory and the handlers
had no entries. A nested function decorated with a route call (.get,
.post, .put, .patch, .delete, .head, .options, .trace, .websocket,
.route, .api_route) is now its own entry, named like an Express route
(`GET /users`, `GET|POST /sync`, `GET /users#2`), in the module's
namespace. Its decisions are not also charged to the factory; the
decorator's arguments still are. A string path must be empty or start
with `/`, so `@mock.patch("a.b")` is not a route. Top-level handlers and
methods keep their names. The `#2` naming moves to treesitter.claim so
both scanners share it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Why
FastAPI and Flask apps often register their handlers inside a factory:
A nested function stays inside the function that encloses it, so every handler's decisions are charged to
build_router. The factory reports a large CC, and the handlers, where the logic and the missing tests are, have no entries. The TypeScript scanner already handles the same shape for inline Express callbacks.What
.get,.post,.put,.patch,.delete,.head,.options,.trace,.websocket,.routeor.api_route) is its own entry in the module's namespace, as an Express callback is.GET /users/{user_id}..routeand.api_routetake their verbs frommethods=[...](GET|POST /sync) and default toGET. A repeated label isGET /users#2./, so@mock.patch("pkg.mod.attr")is not a route. An f-string keeps its fields (GET {PREFIX}/items), and a name keeps its source (DELETE PATHS.user).#2naming moves fromtypescript.pytotreesitter.claim, so both scanners share one copy.Not included
The factory's coverage range still includes the handler bodies, as it does for a function that encloses Express callbacks.
Verified
test_route_handlers_in_a_factory_are_their_own_entriesandtest_top_level_handlers_keep_their_names_and_lookalikes_stay_nestedfail onmasterand pass here.languages/python.pyis at 99% line coverage. The one missed line (ident is None) predates this change.python:3.12-slimwith git and zsh): 147 passed, 1 failed, thebbtest that fails onmastertoo. Windows, Python 3.12: 144 passed, with the same 4 Unix-only failures asmaster.This touches the same README paragraph, module docstring and test file as #29. Whichever lands second needs a small rebase, and I will do it.