Skip to content

Commit

Permalink
add missing methods to DateData and inherit from MutableMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
noviluni committed Sep 16, 2020
1 parent 8672dec commit aa6ef69
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion dateparser/date.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections
from collections import MutableMapping
from collections.abc import Set
from datetime import datetime, timedelta

Expand Down Expand Up @@ -252,7 +253,7 @@ def _is_valid_date_obj(self, date_obj):
return True


class DateData:
class DateData(MutableMapping):
"""
Class that represents the parsed data with useful information.
It can be accessed like a dict object.
Expand Down Expand Up @@ -282,9 +283,23 @@ def __contains__(self, item):
return True
return False

def __len__(self):
return len(self.keys())

def __iter__(self):
yield from self.__dict__.keys()

def __delitem__(self, v):
if not hasattr(self, v):
raise KeyError(v)
setattr(self, v, None)

def keys(self):
return self.__dict__.keys()

def values(self):
return self.__dict__.values()


class DateDataParser:
"""
Expand Down

0 comments on commit aa6ef69

Please sign in to comment.