Skip to content

Commit

Permalink
Fix and deprecate the classes in Mythtv.utility.altdict.py
Browse files Browse the repository at this point in the history
The classes 'DictInvert' and 'DictInvertCI' from this module will be
removed after MythTV v32 release, use the imports
'from MythTV.altdict import DictInvert, DictInvertCI.", instead.

The class 'OrdDict' from the module 'Mythtv.utility.altdict' will be
removed after MythTV v32 release, use the class 'OrderedDict' from
the module 'collections' provided by python3.

Note: MythTV provides the class 'OrdDict' already in the module
MythTV.altdict. There is no need to duplicate or shadow the same
functionality.

Refs #422
  • Loading branch information
rcrdnalor committed Dec 20, 2021
1 parent fb1f828 commit 0dec07d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions mythtv/bindings/python/MythTV/utility/altdict.py
Expand Up @@ -4,7 +4,15 @@
# Description: Provides various custom dict-like classes
#------------------------------

# Important Note: The classes provided by this module are considered deprecated and will be
# removed after the release of MythTV v32!
# Please use the class 'OrderedDict' from the module 'collections' provided
# by python3.
# For the classes 'DictInvert' and 'DictInvertCI', please use the imports
# 'from MythTV.altdict import DictInvert, DictInvertCI'

from builtins import map, zip
from warnings import warn

class OrdDict( dict ):
"""
Expand Down Expand Up @@ -42,13 +50,16 @@ def __delattr__(self, name):
del self[name]

def __delitem__(self, key):
dict.__delitem(self, key)
dict.__delitem__(self, key)
self._field_order.remove(key)

def __iter__(self):
return self.itervalues()

def __init__(self, data=()):
warn("Class 'OrdDict' from this module will be removed after MythTV v32 release, "
"use the class 'OrderedDict' from the module 'collections' provided by python3.",
DeprecationWarning, 2)
dict.__init__(self)
self._field_order = []
for k,v in data:
Expand Down Expand Up @@ -93,9 +104,13 @@ class DictInvert(dict):
"""

def __init__(self, other, mine=None):
warn("Classes 'DictInvert' and 'DictInvertCI' from this module will be removed "
"after MythTV v32 release, "
"use the imports 'from MythTV.altdict import DictInvert, DictInvertCI.",
DeprecationWarning, 2)
self.other = other
if mine is None:
mine = dict(zip(*reversed(zip(*other.items()))))
mine = dict(zip(*reversed(list(zip(*other.items())))))
dict.__init__(self, mine)

@classmethod
Expand Down

0 comments on commit 0dec07d

Please sign in to comment.