File tree Expand file tree Collapse file tree 4 files changed +32
-27
lines changed Expand file tree Collapse file tree 4 files changed +32
-27
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ def entries() -> Iterable[Entry]:
90
90
91
91
def fill_influxdb () -> None :
92
92
from .core .influxdb import magic_fill
93
- from .core .types import Freezer
93
+ from .core .freezer import Freezer
94
94
freezer = Freezer (Entry )
95
95
fit = (freezer .freeze (e ) for e in entries ())
96
96
# TODO crap, influxdb doesn't like None https://github.com/influxdata/influxdb/issues/7722
Original file line number Diff line number Diff line change 2
2
3
3
import dataclasses as dcl
4
4
import inspect
5
- from typing import TypeVar , Type
5
+ from typing import TypeVar , Type , Any
6
6
7
7
D = TypeVar ('D' )
8
8
@@ -40,23 +40,27 @@ def freeze(self, value: D) -> D:
40
40
41
41
### tests
42
42
43
+
44
+ # this needs to be defined here to prevent a mypy bug
45
+ # see https://github.com/python/mypy/issues/7281
46
+ @dcl .dataclass
47
+ class _A :
48
+ x : Any
49
+
50
+ # TODO what about error handling?
51
+ @property
52
+ def typed (self ) -> int :
53
+ return self .x ['an_int' ]
54
+
55
+ @property
56
+ def untyped (self ):
57
+ return self .x ['an_any' ]
58
+
59
+
43
60
def test_freezer () -> None :
44
- from typing import Any
45
- @dcl .dataclass
46
- class A :
47
- x : Any
48
-
49
- # TODO what about error handling?
50
- @property
51
- def typed (self ) -> int :
52
- return self .x ['an_int' ]
53
-
54
- @property
55
- def untyped (self ):
56
- return self .x ['an_any' ]
57
-
58
- val = A (x = dict (an_int = 123 , an_any = [1 , 2 , 3 ]))
59
- af = Freezer (A )
61
+
62
+ val = _A (x = dict (an_int = 123 , an_any = [1 , 2 , 3 ]))
63
+ af = Freezer (_A )
60
64
fval = af .freeze (val )
61
65
62
66
fd = vars (fval )
Original file line number Diff line number Diff line change 1
1
import datetime
2
- from typing import Any , Optional , Callable
2
+ from typing import Any , Optional , Callable , NamedTuple
3
3
from functools import lru_cache
4
4
5
5
from .common import is_namedtuple
@@ -137,17 +137,18 @@ def test_serialize_fallback() -> None:
137
137
138
138
139
139
140
+ # this needs to be defined here to prevent a mypy bug
141
+ # see https://github.com/python/mypy/issues/7281
142
+ class _A (NamedTuple ):
143
+ x : int
144
+ y : float
145
+
146
+
140
147
def test_nt_serialize () -> None :
141
148
import json as jsn # dont cause possible conflicts with module code
142
149
import orjson # import to make sure this is installed
143
150
144
- from typing import NamedTuple
145
-
146
- class A (NamedTuple ):
147
- x : int
148
- y : float
149
-
150
- res : str = dumps (A (x = 1 , y = 2.0 ))
151
+ res : str = dumps (_A (x = 1 , y = 2.0 ))
151
152
assert res == '{"x":1,"y":2.0}'
152
153
153
154
# test orjson option kwarg
Original file line number Diff line number Diff line change 16
16
from my .core .error import *
17
17
from my .core .util import *
18
18
from my .core .discovery_pure import *
19
- from my .core .types import *
19
+ from my .core .freezer import *
20
20
from my .core .stats import *
21
21
from my .core .serialize import test_serialize_fallback
You can’t perform that action at this time.
0 commit comments