Skip to content

Commit

Permalink
Remove BaseBatchFileEncoding.parse method
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Aug 11, 2022
1 parent 5eb785b commit 5a7cb5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 13 additions & 11 deletions singer_sdk/helpers/_singer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import enum
import json
import logging
import sys
from dataclasses import asdict, dataclass, field, fields
Expand Down Expand Up @@ -332,16 +331,6 @@ def from_dict(cls, data: dict[str, Any]) -> BaseBatchFileEncoding:
encoding_cls = cls.registered_encodings[encoding_format]
return encoding_cls(**data)

@classmethod
def parse(cls, value: str, **kwargs: Any):
"""Parse a JSON Lines encoding from a dictionary.
Args:
value: A dictionary containing the encoding.
kwargs: Additional keyword arguments for `json.loads`.
"""
return cls.from_dict(json.loads(value, **kwargs))


@dataclass
class JSONLinesEncoding(BaseBatchFileEncoding):
Expand Down Expand Up @@ -381,3 +370,16 @@ def asdict(self):
A dictionary with the defined message fields.
"""
return asdict(self)

@classmethod
def from_dict(cls, data: dict[str, Any]) -> SDKBatchMessage:
"""Create an encoding from a dictionary.
Args:
data: The dictionary to create the message from.
Returns:
The created message.
"""
data.pop("type")
return cls(**data)
3 changes: 1 addition & 2 deletions tests/core/test_singer_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ def test_batch_message_as_dict(message, expected):
dumped = message.asdict()
assert dumped == expected

dumped.pop("type")
assert message.__class__(**dumped) == message
assert message.from_dict(dumped) == message

0 comments on commit 5a7cb5f

Please sign in to comment.