python-injector / python-injector/injector

Only inject objects with the @inject decorator and objects with a @provider

Open
#116 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
94
PR merge metrics
No merged PRs in 30d

Description

Edit: This post originally had a question on how to solve a specific problem, but is updated with the solution and requested change described in https://github.com/alecthomas/injector/issues/116#issuecomment-647505337:

Injector should require a @provider or a constructor with the @inject decorator for an object to be created.

The original post is kept below.


As mentioned before in #78, I feel that the way Injector has default values for "value types" such as such as str, int and bool is pretty counter-intuitive, and therefore risky. Removing that would obviously break backwards compatibility, but I'd like you to consider that.

To me, the use case for Injector is primarily to inject dependent classes. It is in some cases also useful to configure these classes with parameters that may be value types, but commonly the values shouldn't be the same for every every class they configure.

Is there a design decision behind the current behavior, or is it rather a consequence of the implementation?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are named in the issue. Start by tracing how Injector currently creates objects and handles @provider and @inject, then inspect existing tests for constructor injection and providers. Done means un-decorated constructors are not implicitly used, while explicitly provided or @inject-decorated objects remain creatable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.