Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: return class in injectable decorator (#59)
* fix: return class in injectable decorator # Proposal Linked to #58 The issue with the Injectable decorator returning a string instead of the class itself likely stems from the decorator definition. In the definition of Injectable, cls is treated as if it could potentially be a string (cls: str = None), which suggests that the decorator might be designed to accept optional parameters or configurations. However, if not handled properly, this design could lead to unexpected behavior, such as treating a class definition as a string. # Correcting the Injectable Decorator The decorator needs to correctly handle both cases: when it is used with and without parameters. Here’s a more standard way of creating a decorator that can optionally accept arguments # Explanation 1. Decorator Factory: The Injectable function can now correctly handle being called either as @Injectable or @Injectable(). It uses a nested decorator function to apply the actual class modifications. 2. Class Modifications: It checks if the class has an __init__ method defined and, if not, assigns a default one. It then parses dependencies, sets necessary attributes, and applies injection. 3. Handling Arguments: The outer function (Injectable) checks if it is given a class directly (cls is not None). If so, it directly returns the decorator applied to the class. Otherwise, it returns the decorator function itself, allowing for further customization or arguments. * fix: use elipsis instead of pass
- Loading branch information