Skip to content

Respect class-level singleton decorators in multibindings - #332

Open
boyfeiyu wants to merge 1 commit into
python-injector:masterfrom
boyfeiyu:BOYF-485-decorated-singleton-multibind
Open

boyfeiyu wants to merge 1 commit into
python-injector:masterfrom
boyfeiyu:BOYF-485-decorated-singleton-multibind

Conversation

@boyfeiyu

@boyfeiyu boyfeiyu commented Nov 5, 2026

Copy link
Copy Markdown

Repeated contributions of the same @singleton class currently create separate objects within multibound lists and dictionaries. Respect the class decorator by sharing a class-specific cache key within each collection, and apply the scope to dictionary values before wrapping them with their keys.

Explicit binding scopes keep their existing per-contribution behavior, including scope=singleton and scope=noscope. Ordinary bindings, other provider kinds, and custom scopes retain their existing behavior.

Fixes #298. The regression test comes from @davidparsson's open draft #292, which currently contains the test without a production fix. This change does not implement the parent/child collection extension proposed in #324.

Validation on CPython 3.12.14 / macOS arm64:

  • Full suite: 152 passed, 97.19% coverage.
  • The original list regression and a separate replay of its dictionary assertion fail on current master and pass with this change.
  • 25 additional independent checks passed, including construction counts, repeated/concurrent lookups, explicit scopes, dictionary keys, and injector isolation.
  • mypy 1.7.1, Black 26.10.1, and check-manifest --no-build-isolation passed, using the repository's declared tool versions.

The other Python/PyPy and Linux CI environments have not been run locally.

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.93%. Comparing base (3177d40) to head (e6b3e74).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #332      +/-   ##
==========================================
+ Coverage   96.83%   96.93%   +0.09%     
==========================================
  Files           1        1              
  Lines         601      619      +18     
  Branches      103      106       +3     
==========================================
+ Hits          582      600      +18     
  Misses         13       13              
  Partials        6        6              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Multibind should respect the @singleton decorator

1 participant