Skip to content

Commit

Permalink
updated list comprehensions for dict to be compatible with Python 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
darthbear committed Apr 28, 2015
1 parent 8439dec commit 4dcd8b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions catdb/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ def __init__(self, dbname, params={}):
mappings = ConfigFactory().parse_file(pkg_resources.resource_filename(__name__, 'mappings.conf'))

# mapping coltype => {mapping} instead of coltype => db => {mapping}
self._mappings = {k: d[dbname] for k, d in mappings['mappings'].items()}
# dict() list comprehension compatible with Python 2.6 (does not support {k:v for ...})
self._mappings = dict((k, d[dbname]) for k, d in mappings['mappings'].items())

# reverse mapping
self._rev_mappings = {
d[dbname]['type']: {
self._rev_mappings = dict((d[dbname]['type'], {
'type': k,
'defaults': {
dv: dk for dk, dv in d[dbname].get('defaults', {}).items()
}
} for k, d in mappings['mappings'].items()
}
'defaults': dict((dv, dk) for dk, dv in d[dbname].get('defaults', {}).items())
}) for k, d in mappings['mappings'].items()
)

@abstractmethod
def list_tables(self, schema=None, table_filter=None):
Expand Down Expand Up @@ -55,7 +53,7 @@ def get_column_def(entry):
}

# remove null values
return {k: v for k, v in row.items() if v is not None}
return dict((k, v) for k, v in row.items() if v is not None)

def get_table_def(table):
meta = self.get_column_info(schema, table)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run_tests(self):
'psycopg2==2.6',
'boto3==0.0.16',
'PyMySQL==0.6.6'
],
] + ['importlib==1.0.3'] if sys.version_info[:2] == (2, 6) else [],
tests_require=[
'pytest',
'mock'
Expand Down

0 comments on commit 4dcd8b7

Please sign in to comment.