comparison roundup/support.py @ 5442:afd9fd3a0edb

Python 3 preparation: avoid assigning to instance __getitem__ in TruthDict. In Python 3, special method names are generally only looked up at the class level, not on instance objects, and so assigning to them for an instance object doesn't work as expected.
author Joseph Myers <jsm@polyomino.org.uk>
date Wed, 25 Jul 2018 12:29:08 +0000
parents 2120f77554d5
children 01643d37785f
comparison
equal deleted inserted replaced
5441:a14c0e652e25 5442:afd9fd3a0edb
13 def __init__(self, keys): 13 def __init__(self, keys):
14 if keys: 14 if keys:
15 self.keys = {} 15 self.keys = {}
16 for col in keys: 16 for col in keys:
17 self.keys[col] = 1 17 self.keys[col] = 1
18 else:
19 self.__getitem__ = lambda name: 1
20 18
21 def __getitem__(self, name): 19 def __getitem__(self, name):
22 return name in self.keys 20 if hasattr(self, 'keys'):
21 return name in self.keys
22 else:
23 return True
23 24
24 def ensureParentsExist(dest): 25 def ensureParentsExist(dest):
25 if not os.path.exists(os.path.dirname(dest)): 26 if not os.path.exists(os.path.dirname(dest)):
26 os.makedirs(os.path.dirname(dest)) 27 os.makedirs(os.path.dirname(dest))
27 28

Roundup Issue Tracker: http://roundup-tracker.org/