Skip to content

feat(application): route and class discovery accept a single module - #341

Merged
mofr merged 1 commit into
masterfrom
discovery-accepts-modules
Oct 13, 2026
Merged

mofr merged 1 commit into
masterfrom
discovery-accepts-modules

Conversation

@mofr

@mofr mofr commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

winter.web.find_package_routes and get_all_classes accepted only a package. import_recursively read __path__, so a module name failed with AttributeError. A project that wants its API in myapp/api.py had to turn it into a subpackage just for discovery.

Now a module name yields that module. Packages behave as before.

The ownership check is tightened in the same function. A class counted as found when its __module__ merely started with the scanned name, so scanning myapp.api would also pick classes imported from a sibling myapp.api_utils. Now the module must be the scanned name or below it. For packages this only removes such false positives.

The change also applies to the event and domain event autodiscovery, which use get_all_classes.

Motivation: WinterFramework/winter-getting-started#7 wants a flat simple_api/api.py and simple_api/openapi.py.

Tests: discovery of a module, of a package, and the sibling-prefix case; both module tests fail without the change. Coverage is complete except Redis, which needs Docker locally.

🤖 Generated with Claude Code

find_package_routes and get_all_classes took only a package: import_recursively read
__path__, which a module lacks. A module name now yields that module, so a flat project
can scan myapp.api without moving it into a subpackage.

A class counts as defined in the scanned package or module only when its module is that
name or below it. The plain prefix check also matched a sibling such as myapp.api_utils.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mofr
mofr merged commit 88d1c23 into master Oct 13, 2026
8 checks passed
@mofr
mofr deleted the discovery-accepts-modules branch October 13, 2026 11:34
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.

2 participants