Skip to content

Commit a4e40b0

Browse files
Made some serialization params options.
1 parent 19dac4b commit a4e40b0

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

edq/net/exchange.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def hash_content(self) -> str:
156156
return edq.util.hash.sha256_hex(hash_content)
157157

158158
def to_dict(self,
159-
context: edq.util.serial.SerializationContext,
159+
context: typing.Union[edq.util.serial.SerializationContext, None] = None,
160160
) -> typing.Dict[str, typing.Any]:
161161
data = vars(self).copy()
162162

@@ -587,7 +587,7 @@ def compute_relpath(self, http_exchange_extension: str = DEFAULT_HTTP_EXCHANGE_E
587587
return os.path.join(dirname, filename)
588588

589589
def to_dict(self,
590-
context: edq.util.serial.SerializationContext,
590+
context: typing.Union[edq.util.serial.SerializationContext, None] = None,
591591
) -> typing.Dict[str, typing.Any]:
592592
return vars(self)
593593

edq/util/serial.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ class PODSerializer(SerializationBase):
7373
"""
7474

7575
def to_pod(self,
76-
context: SerializationContext,
76+
context: typing.Union[SerializationContext, None] = None,
7777
) -> PODType:
7878
"""
7979
Get a POD representation of this object.
8080
8181
The default implementation will convert to a dict (similar to a DictSerializer).
8282
"""
8383

84+
if (context is None):
85+
context = SerializationContext()
86+
8487
data: typing.Dict[str, typing.Any] = {}
8588

8689
for (key, value) in vars(self).items():
@@ -222,11 +225,11 @@ def copy(self,
222225
context: typing.Union[SerializationContext, None] = None,
223226
) -> 'PODConverter':
224227
"""
225-
Make a copy of this object.
228+
Make a deep copy of this object.
226229
The default implementation will use to_pod() and from_pod() to make a copy.
227230
228-
This copy may be shallow or deep depending on the underlying class,
229-
but implementers should favor deep copies.
231+
Callers should be cautious of fileds that are skipped in serialization,
232+
e.g., via `SerializationBase.serialization_skip_fields`.
230233
"""
231234

232235
if (context is None):
@@ -245,7 +248,7 @@ class DictSerializer(PODSerializer):
245248
"""
246249

247250
def to_dict(self,
248-
context: SerializationContext,
251+
context: typing.Union[SerializationContext, None] = None,
249252
) -> typing.Dict[str, typing.Any]:
250253
"""
251254
Return a dict that can be used to represent this object.

edq/util/serial_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self,
3232
self.value: str = value
3333

3434
def to_pod(self,
35-
context: edq.util.serial.SerializationContext,
35+
context: typing.Union[edq.util.serial.SerializationContext, None] = None,
3636
) -> str:
3737
return self.value
3838

edq/util/time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def guess(value: typing.Any) -> 'Timestamp':
228228
return Timestamp.from_pytime(value)
229229

230230
def to_pod(self,
231-
context: edq.util.serial.SerializationContext,
231+
context: typing.Union[edq.util.serial.SerializationContext, None] = None,
232232
) -> int:
233233
return self
234234

0 commit comments

Comments
 (0)