Skip to content

Commit f67c8d7

Browse files
author
Bartek Ogryczak
committed
similar optimization for Table class
1 parent 287e5d2 commit f67c8d7

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

pymysqlreplication/column.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def __ne__(self, other):
8383
return not self.__eq__(other)
8484

8585
def serializable_data(self):
86-
return dict((k, v) for (k, v) in self.__dict__.items() if not k.startswith('_'))
86+
return self.data
8787

8888
@property
8989
def data(self):
90-
return self.serializable_data()
90+
return dict((k, v) for (k, v) in self.__dict__.items() if not k.startswith('_'))

pymysqlreplication/table.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class Table(object):
5-
def __init__(self, column_schemas, table_id, schema, table, columns, primary_key = None):
5+
def __init__(self, column_schemas, table_id, schema, table, columns, primary_key=None):
66
if primary_key is None:
77
primary_key = [c.data["name"] for c in columns if c.data["is_primary"]]
88
if len(primary_key) == 0:
@@ -12,26 +12,24 @@ def __init__(self, column_schemas, table_id, schema, table, columns, primary_key
1212
else:
1313
primary_key = tuple(primary_key)
1414

15-
self.data = {
15+
self.__dict__.update({
1616
"column_schemas": column_schemas,
1717
"table_id": table_id,
1818
"schema": schema,
1919
"table": table,
2020
"columns": columns,
2121
"primary_key": primary_key
22-
}
22+
})
2323

24-
def __getattr__(self, item):
25-
try:
26-
return self.data[item]
27-
except KeyError:
28-
raise AttributeError
24+
@property
25+
def data(self):
26+
return dict((k, v) for (k, v) in self.__dict__.items() if not k.startswith('_'))
2927

3028
def __eq__(self, other):
3129
return self.data == other.data
3230

3331
def __ne__(self, other):
34-
return self.__eq__(other)
32+
return not self.__eq__(other)
3533

3634
def serializable_data(self):
3735
return self.data

0 commit comments

Comments
 (0)