Skip to content

Commit

Permalink
refactor(utility): remove "loads" and "dumps" from "NameMixin"
Browse files Browse the repository at this point in the history
`DatasetBase` and `SegmentBase` are subclasses of `NameMixin`, but they
do not support `loads` and `dumps` methods. Remove `loads` and `dumps`
from `NameMixin` to make sure they cannot be called from `DatasetBase`
and `SegmentBase`

PR Closed: #738
  • Loading branch information
linjiX committed Jun 19, 2021
1 parent a575d8b commit d11b7b3
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions tensorbay/utility/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
"""

from bisect import bisect_left, bisect_right
from typing import Any, Dict, Iterable, List, Tuple, Type, TypeVar, Union, overload
from typing import Any, Dict, Iterable, List, Tuple, TypeVar, Union, overload

from .attr import AttrsMixin, attr
from .common import common_loads
from .repr import ReprMixin
from .user import UserSequence


class NameMixin(AttrsMixin, ReprMixin):
class NameMixin(AttrsMixin, ReprMixin): # pylint: disable=too-few-public-methods
"""A mixin class for instance which has immutable name and mutable description.
Arguments:
Expand All @@ -47,39 +46,6 @@ def __init__(self, name: str, description: str = "") -> None:
def _repr_head(self) -> str:
return f'{self.__class__.__name__}("{self._name}")'

def dumps(self) -> Dict[str, str]:
"""Dumps the instance into a dict.
Returns:
A dict containing the name and the description,
whose format is like::
{
"name": <str>
"description": <str>
}
"""
return self._dumps()

@classmethod
def loads(cls: Type[_P], contents: Dict[str, str]) -> _P:
"""Loads a NameMixin from a dict containing the information of the NameMixin.
Arguments:
contents: A dict containing the information of the :class:`NameMixin`::
{
"name": <str>
"description": <str>
}
Returns:
A :class:`NameMixin` instance containing the information from the contents dict.
"""
return common_loads(cls, contents)

@property
def name(self) -> str:
"""Return name of the instance.
Expand Down

0 comments on commit d11b7b3

Please sign in to comment.