-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeps.py
More file actions
30 lines (19 loc) · 740 Bytes
/
deps.py
File metadata and controls
30 lines (19 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import get_type_hints
from attr import attrs as original_attrs, Factory
import inject
__all__ = ('attributes', 'attrs', 's', 'Interface')
__version__ = '0.2'
class Interface:
pass
def attrs(*args, **kwargs):
def wrap(cls):
hints = get_type_hints(cls)
for property_name, property_type in hints.items():
if isinstance(property_type, type) and issubclass(property_type, Interface):
def _factory(klass):
return lambda: inject.instance(klass)
setattr(cls, property_name, Factory(_factory(property_type)))
kwargs['auto_attribs'] = True
return original_attrs(*args, **kwargs)(cls)
return wrap
s = attributes = attrs