Skip to content

Commit

Permalink
revert: rename representation to identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ committed Mar 10, 2022
1 parent 620b20d commit b669bc4
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions znjson/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ConverterBase(abc.ABC):
----------
instance: type
the type of the object to convert, e.g. np.ndarray or pathlib.Path
identifier: str
representation: str
the name of the object to convert. should e.g. be `pathlib.Path`
level: int
The level in which the encoding should be applied. A higher number means it will
Expand All @@ -19,7 +19,7 @@ class ConverterBase(abc.ABC):
"""

instance: type = None
identifier: str = None
representation: str = None
level: int = 0

@abc.abstractmethod
Expand Down Expand Up @@ -68,12 +68,12 @@ def encode(self, obj) -> dict:
Returns
-------
dict:
A dictionary {_type: self.identifier, value: serialized_obj}
A dictionary {_type: self.representation, value: serialized_obj}
"""

if self == obj:
return {"_type": self.identifier, "value": self._encode(obj)}
return {"_type": self.representation, "value": self._encode(obj)}
else:
raise NotImplementedError(f"{self.__class__} can't convert {type(obj)}")

Expand All @@ -83,7 +83,7 @@ def decode(self, obj: dict):
Parameters
----------
obj: dict
A dictionary {_type: self.identifier, value: serialized_obj}
A dictionary {_type: self.representation, value: serialized_obj}
Returns
-------
Expand All @@ -95,7 +95,7 @@ def decode(self, obj: dict):
_ = obj["_type"]
except KeyError:
raise NotImplementedError(f"{self.__class__} can't convert without _type")
if obj["_type"] == self.identifier:
if obj["_type"] == self.representation:
return self._decode(obj["value"])
else:
raise NotImplementedError(f"{self.__class__} can't convert {obj['_type']}")
Expand Down
2 changes: 1 addition & 1 deletion znjson/converter/class_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ClassConverter(ConverterBase):
instance = object
identifier = "class"
representation = "class"
level = 0

def _encode(self, obj):
Expand Down
2 changes: 1 addition & 1 deletion znjson/converter/numpy_converter_base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class NumpyConverter(ConverterBase):
instance = np.ndarray
identifier = "np.ndarray64"
representation = "np.ndarray64"
level = 30

def _encode(self, obj):
Expand Down
2 changes: 1 addition & 1 deletion znjson/converter/numpy_converter_latin1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class NumpyConverterLatin1(ConverterBase):
"""Do not use"""

instance = np.ndarray
identifier = "np.ndarray"
representation = "np.ndarray"
level = 0

def _encode(self, obj):
Expand Down
2 changes: 1 addition & 1 deletion znjson/converter/pandas_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class PandasConverter(ConverterBase):
instance = pandas.DataFrame
identifier = "pandas.DataFrame"
representation = "pandas.DataFrame"
level = 10

def _encode(self, obj: pandas.DataFrame):
Expand Down
2 changes: 1 addition & 1 deletion znjson/converter/pathlib_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class PathlibConverter(ConverterBase):
instance = pathlib.Path
identifier = "pathlib.Path"
representation = "pathlib.Path"
level = 10

def _encode(self, obj: pathlib.Path):
Expand Down
2 changes: 1 addition & 1 deletion znjson/converter/small_numpy_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class SmallNumpyConverter(ConverterBase):
instance = np.ndarray
identifier = "np.ndarray_small"
representation = "np.ndarray_small"
level = 50

def _encode(self, obj):
Expand Down
2 changes: 1 addition & 1 deletion znjson/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def object_hook(self, obj):
return obj
config.sort()
for converter in config.ACTIVE_CONVERTER:
if converter.identifier == instance:
if converter.representation == instance:
return converter().decode(obj)
raise TypeError(f"Object of type {instance} could not be converted")

Expand Down

0 comments on commit b669bc4

Please sign in to comment.