Conversation
… in injection functions
… in debug functions
This commit deprecates the use of dictionaries as scopes in favor of the new `fundi.Scope` object. This change makes dependency injection scopes more explicit, robust, and feature-rich. The new `fundi.Scope` provides three distinct stores for dependency resolution: - Named values: For resolving dependencies by parameter name. - Typed instances: For resolving dependencies by type annotation. - Type factories: For creating instances on-demand when resolved by type. Key changes include: - Introduction of the `fundi.Scope` and `fundi.Type` classes. - Updates across all documentation and examples to adopt the new `Scope` object. - A complete rewrite of the scope documentation (`docs/howtos/scope.rst`) to explain the new features. - Exposure of `Scope` and `Type` in the top-level `fundi` namespace. - Minor fixes to docstrings for better rendering.
This change refactors `configurable_dependency` to be more type-safe and explicit by introducing two new protocols: `DependencyConfiguratorProtocol` and `ConfiguredDependencyProtocol`. `DependencyConfiguratorProtocol` types the decorator itself, indicating that it returns a `ConfiguredDependencyProtocol`. `ConfiguredDependencyProtocol` types the configured dependency, ensuring it has the `__fundi_configuration__` attribute. The original configurator is now stored in the `origin` attribute of the wrapped function, allowing for better introspection.
In `fundi.scan.scan`, the returned `CallableInfo` object's `side_effects` attribute was being populated with the raw, unscanned functions that were passed in. This has been corrected to use the list of internally processed `SideEffect` objects, ensuring downstream consumers receive the properly scanned side effects. The list is converted to a tuple to ensure immutability of the `CallableInfo`. Additionally, minor code cleanup was performed, removing unused imports from a test file and a debug print statement.
The `Scope.add_factory` method has been significantly improved to be more flexible and easier to use. Key enhancements include: 1. **Pass-through Scan Parameters:** It's now possible to pass all parameters from the `scan()` function (e.g., `caching`, `async_`, `generator`) directly to `add_factory`. This allows for fine-grained control over how the factory is scanned and how its results are cached, without needing to call `scan()` manually. 2. **Automatic Type Inference:** The `type_` parameter is now optional. If it's not provided, `add_factory` will automatically infer the dependency type from the factory's return annotation, reducing boilerplate code. A `ValueError` is raised if the type cannot be inferred. The tests and documentation have been updated to reflect these new capabilities.
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.
No description provided.