Created
August 20, 2014 19:49
-
-
Save slezica/a27fb82e66c629930e56 to your computer and use it in GitHub Desktop.
Detect unused keys in configuration dicts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrackingDict(dict): | |
instances = [] | |
def __init__(self, dct): | |
super(TrackingDict, self).__init__(dct) | |
self.used_keys = [] | |
TrackingDict.instances.append(self) | |
def __getitem__(self, key): | |
self.used_keys.append(key) | |
return super(TrackingDict, self).__getitem__(key) | |
@staticmethod | |
def deadItems(): | |
return [ | |
[key for key in instance if key not in instance.used_keys] | |
for instance in TrackingDict.instances | |
] | |
print TrackingDict.deadItems() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Posta
Pavadas
Dudas
sh
?