@@ -35,6 +35,19 @@ def include(source: str):
35
35
"__includes" , []).append (source )
36
36
37
37
38
+ class _Namespace :
39
+ """ simple namespacing mechanism """
40
+
41
+ def __init__ (self , ** kwargs ):
42
+ self .__dict__ .update (kwargs )
43
+
44
+
45
+ qltest = _Namespace ()
46
+ ql = _Namespace ()
47
+ cpp = _Namespace ()
48
+ synth = _Namespace ()
49
+
50
+
38
51
@_dataclass
39
52
class _Pragma (_schema .PropertyModifier ):
40
53
""" A class or property pragma.
@@ -43,6 +56,10 @@ class _Pragma(_schema.PropertyModifier):
43
56
"""
44
57
pragma : str
45
58
59
+ def __post_init__ (self ):
60
+ namespace , _ , name = self .pragma .partition ('_' )
61
+ setattr (globals ()[namespace ], name , self )
62
+
46
63
def modify (self , prop : _schema .Property ):
47
64
prop .pragmas .append (self .pragma )
48
65
@@ -86,13 +103,6 @@ def __getitem__(self, item):
86
103
return item | self .modifier
87
104
88
105
89
- class _Namespace :
90
- """ simple namespacing mechanism """
91
-
92
- def __init__ (self , ** kwargs ):
93
- self .__dict__ .update (kwargs )
94
-
95
-
96
106
_ClassDecorator = _Callable [[type ], type ]
97
107
98
108
@@ -119,28 +129,20 @@ def f(cls: type) -> type:
119
129
120
130
use_for_null = _annotate (null = True )
121
131
122
- qltest = _Namespace (
123
- skip = _Pragma ("qltest_skip" ),
124
- collapse_hierarchy = _Pragma ("qltest_collapse_hierarchy" ),
125
- uncollapse_hierarchy = _Pragma ("qltest_uncollapse_hierarchy" ),
126
- )
132
+ _Pragma ("qltest_skip" )
133
+ _Pragma ("qltest_collapse_hierarchy" )
134
+ _Pragma ("qltest_uncollapse_hierarchy" )
127
135
128
- ql = _Namespace (
129
- default_doc_name = lambda doc : _annotate (doc_name = doc )
130
- )
136
+ ql .default_doc_name = lambda doc : _annotate (doc_name = doc )
131
137
132
- cpp = _Namespace (
133
- skip = _Pragma ("cpp_skip" ),
134
- )
138
+ _Pragma ("cpp_skip" )
135
139
136
140
137
141
def group (name : str = "" ) -> _ClassDecorator :
138
142
return _annotate (group = name )
139
143
140
144
141
- synth = _Namespace (
142
- from_class = lambda ref : _annotate (ipa = _schema .IpaInfo (
143
- from_class = _schema .get_type_name (ref ))),
144
- on_arguments = lambda ** kwargs : _annotate (
145
- ipa = _schema .IpaInfo (on_arguments = {k : _schema .get_type_name (t ) for k , t in kwargs .items ()}))
146
- )
145
+ synth .from_class = lambda ref : _annotate (ipa = _schema .IpaInfo (
146
+ from_class = _schema .get_type_name (ref )))
147
+ synth .on_arguments = lambda ** kwargs : _annotate (
148
+ ipa = _schema .IpaInfo (on_arguments = {k : _schema .get_type_name (t ) for k , t in kwargs .items ()}))
0 commit comments