@@ -261,14 +261,6 @@ def get_default(cls):
261
261
262
262
@dataclass (repr = False , eq = False , frozen = True , slots = True )
263
263
class Module (EventListener ):
264
- """
265
- Object with isolated injection environment.
266
-
267
- Modules have been designed to simplify unit test writing. So think carefully before
268
- instantiating a new one. They could increase complexity unnecessarily if used
269
- extensively.
270
- """
271
-
272
264
name : str = field (default = None )
273
265
__channel : EventChannel = field (default_factory = EventChannel , init = False )
274
266
__container : Container = field (default_factory = Container , init = False )
@@ -298,34 +290,14 @@ def __str__(self) -> str:
298
290
299
291
@property
300
292
def inject (self ) -> InjectDecorator :
301
- """
302
- Decorator applicable to a class or function. Inject function dependencies using
303
- parameter type annotations. If applied to a class, the dependencies resolved
304
- will be those of the `__init__` method.
305
- """
306
-
307
293
return InjectDecorator (self )
308
294
309
295
@property
310
296
def injectable (self ) -> InjectableDecorator :
311
- """
312
- Decorator applicable to a class or function. It is used to indicate how the
313
- injectable will be constructed. At injection time, a new instance will be
314
- injected each time. Automatically injects constructor dependencies, can be
315
- disabled with `auto_inject=False`.
316
- """
317
-
318
297
return InjectableDecorator (self , NewInjectable )
319
298
320
299
@property
321
300
def singleton (self ) -> InjectableDecorator :
322
- """
323
- Decorator applicable to a class or function. It is used to indicate how the
324
- singleton will be constructed. At injection time, the injected instance will
325
- always be the same. Automatically injects constructor dependencies, can be
326
- disabled with `auto_inject=False`.
327
- """
328
-
329
301
return InjectableDecorator (self , SingletonInjectable )
330
302
331
303
@property
@@ -338,11 +310,6 @@ def __brokers(self) -> Iterator[Container | Module]:
338
310
yield self .__container
339
311
340
312
def get_instance (self , cls : type [_T ]) -> _T | None :
341
- """
342
- Function used to retrieve an instance associated with the type passed in
343
- parameter or return `None`.
344
- """
345
-
346
313
try :
347
314
injectable = self [cls ]
348
315
except KeyError :
@@ -360,12 +327,6 @@ def use(
360
327
module : Module ,
361
328
priority : ModulePriorities = ModulePriorities .get_default (),
362
329
):
363
- """
364
- Function for using another module. Using another module replaces the module's
365
- dependencies with those of the module used. If the dependency is not found, it
366
- will be searched for in the module's dependency container.
367
- """
368
-
369
330
if module is self :
370
331
raise ModuleError ("Module can't be used by itself." )
371
332
@@ -382,10 +343,6 @@ def use(
382
343
return self
383
344
384
345
def stop_using (self , module : Module ):
385
- """
386
- Function to remove a module in use.
387
- """
388
-
389
346
event = ModuleRemoved (self , module )
390
347
391
348
with suppress (KeyError ):
@@ -401,23 +358,11 @@ def use_temporarily(
401
358
module : Module ,
402
359
priority : ModulePriorities = ModulePriorities .get_default (),
403
360
) -> ContextManager | ContextDecorator :
404
- """
405
- Context manager or decorator for temporary use of a module.
406
- """
407
-
408
361
self .use (module , priority )
409
362
yield
410
363
self .stop_using (module )
411
364
412
365
def change_priority (self , module : Module , priority : ModulePriorities ):
413
- """
414
- Function for changing the priority of a module in use.
415
- There are two priority values:
416
-
417
- * **LOW**: The module concerned becomes the least important of the modules used.
418
- * **HIGH**: The module concerned becomes the most important of the modules used.
419
- """
420
-
421
366
event = ModulePriorityUpdated (self , module , priority )
422
367
423
368
with self .notify (event ):
@@ -426,10 +371,6 @@ def change_priority(self, module: Module, priority: ModulePriorities):
426
371
return self
427
372
428
373
def unlock (self ):
429
- """
430
- Function to unlock the module by deleting cached instances of singletons.
431
- """
432
-
433
374
for broker in self .__brokers :
434
375
broker .unlock ()
435
376
@@ -581,8 +522,7 @@ def wrapper(*args, **kwargs):
581
522
return wrapper
582
523
583
524
def __class_decorator (self , cls : type , / ) -> type :
584
- init_function = type .__getattribute__ (cls , "__init__" )
585
- type .__setattr__ (cls , "__init__" , self .__decorator (init_function ))
525
+ cls .__init__ = self .__decorator (cls .__init__ )
586
526
return cls
587
527
588
528
def __new_binder (self , function : Callable [..., Any ]) -> Binder :
@@ -605,6 +545,7 @@ def __call__(
605
545
self ,
606
546
wrapped : Callable [..., Any ] = None ,
607
547
/ ,
548
+ * ,
608
549
on : type | Iterable [type ] = None ,
609
550
auto_inject : bool = True ,
610
551
):
@@ -632,7 +573,7 @@ def classes():
632
573
return decorator (wrapped ) if wrapped else decorator
633
574
634
575
@staticmethod
635
- def __get_target_class (wrapped : Callable [..., Any ], / ) -> type | None :
576
+ def __get_target_class (wrapped : Callable [..., Any ]) -> type | None :
636
577
if isinstance (wrapped , type ):
637
578
return wrapped
638
579
0 commit comments