6
6
"""
7
7
8
8
from collections .abc import AsyncGenerator
9
- from dataclasses import InitVar , dataclass , field
9
+ from dataclasses import dataclass
10
10
11
11
from nodestream .pipeline import Extractor
12
12
@@ -30,22 +30,12 @@ def _dict_val_to_bool(d: dict[str, any], key: str) -> bool:
30
30
31
31
@dataclass
32
32
class CollectWhichRepos :
33
- org_all : InitVar [bool ] = field (default = False )
34
- user_all : InitVar [bool ] = field (default = False )
35
33
all_public : bool = False
36
34
org_public : bool = False
37
35
org_private : bool = False
38
36
user_public : bool = False
39
37
user_private : bool = False
40
38
41
- def __post_init__ (self , org_all : bool , user_all : bool ):
42
- if org_all :
43
- self .org_public = True
44
- self .org_private = True
45
- if user_all :
46
- self .user_public = True
47
- self .user_private = True
48
-
49
39
@property
50
40
def org_any (self ) -> bool :
51
41
return self .org_public or self .org_private
@@ -54,6 +44,19 @@ def org_any(self) -> bool:
54
44
def user_any (self ) -> bool :
55
45
return self .user_public or self .user_private
56
46
47
+ @staticmethod
48
+ def from_dict (raw_dict : dict [str , any ]) -> "CollectWhichRepos" :
49
+ org_all = _dict_val_to_bool (raw_dict , "org_all" )
50
+ user_all = _dict_val_to_bool (raw_dict , "user_all" )
51
+
52
+ return CollectWhichRepos (
53
+ all_public = _dict_val_to_bool (raw_dict , "all_public" ),
54
+ org_public = org_all or _dict_val_to_bool (raw_dict , "org_public" ),
55
+ org_private = org_all or _dict_val_to_bool (raw_dict , "org_private" ),
56
+ user_public = user_all or _dict_val_to_bool (raw_dict , "user_public" ),
57
+ user_private = user_all or _dict_val_to_bool (raw_dict , "user_private" ),
58
+ )
59
+
57
60
58
61
class GithubReposExtractor (Extractor ):
59
62
def __init__ (
@@ -64,7 +67,7 @@ def __init__(
64
67
if isinstance (collecting , CollectWhichRepos ):
65
68
self .collecting = collecting
66
69
elif isinstance (collecting , dict ):
67
- self .collecting = CollectWhichRepos ( ** collecting )
70
+ self .collecting = CollectWhichRepos . from_dict ( collecting )
68
71
else :
69
72
self .collecting = CollectWhichRepos ()
70
73
self .client = GithubRestApiClient (** kwargs )
0 commit comments