From 0dd2ef2f1d896dbf1f7f50e5020c71f7b906b3ee Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Sun, 3 Jan 2016 09:28:45 +0100 Subject: [PATCH] Style --- relational/maintenance.py | 2 +- relational/optimizations.py | 1 + relational/parser.py | 11 ++++++----- relational/relation.py | 13 ++++++++----- relational/rtypes.py | 7 +++++-- relational_gui/guihandler.py | 21 +++++++++++++++------ 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/relational/maintenance.py b/relational/maintenance.py index c96077a..6bfa0bf 100644 --- a/relational/maintenance.py +++ b/relational/maintenance.py @@ -95,7 +95,7 @@ class UserInterface (object): as bytes. ''' if filename: - with open(filename,'w') as f: + with open(filename, 'w') as f: pickle.dump(self.relations, f) return None return pickle.dumps(self.relations) diff --git a/relational/optimizations.py b/relational/optimizations.py index 49aff5a..489fee0 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -508,6 +508,7 @@ def select_union_intersect_subtract(n): return changes + recoursive_scan(select_union_intersect_subtract, n) + def union_and_product(n): ''' A * B ∪ A * C = A * (B ∪ C) diff --git a/relational/parser.py b/relational/parser.py index 4fa7fa8..e1784cd 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -341,11 +341,12 @@ def tokenize(expression): expression = expression[ par:].strip() # Removing parameter from the expression else: # Relation (hopefully) - expression+=' ' #To avoid the special case of the ending + expression += ' ' # To avoid the special case of the ending - #Initial part is a relation, stop when the name of the relation is over - for r in range(1,len(expression)): - if rtypes.RELATION_NAME_REGEXP.match(expression[:r+1]) is None: + # Initial part is a relation, stop when the name of the relation is + # over + for r in range(1, len(expression)): + if rtypes.RELATION_NAME_REGEXP.match(expression[:r + 1]) is None: break items.append(expression[:r]) expression = expression[r:].strip() @@ -371,5 +372,5 @@ if __name__ == "__main__": e = input("Expression: ") print (parse(e)) -#Backwards compatibility +# Backwards compatibility node = Node diff --git a/relational/relation.py b/relational/relation.py index d8a8ce5..8771d3f 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -64,6 +64,7 @@ class Relation (object): self.header = Header(next(reader)) # read 1st line iterator = ((self.insert(i) for i in reader)) deque(iterator, maxlen=0) + def _make_duplicate(self, copy): '''Flag that the relation "copy" is pointing to the same set as this relation.''' @@ -393,7 +394,7 @@ class Relation (object): m_len = [len(i) for i in self.header] # Maximum lenght string for f in self.content: - for col,i in enumerate(f): + for col, i in enumerate(f): if len(i) > m_len[col]: m_len[col] = len(i) @@ -403,7 +404,7 @@ class Relation (object): for r in self.content: res += "\n" - for col,i in enumerate(r): + for col, i in enumerate(r): res += "%s" % (i.ljust(2 + m_len[col])) return res @@ -426,12 +427,14 @@ class Relation (object): affected = self.selection(expr) not_affected = self.difference(affected) - new_values = tuple(zip(self.header.getAttributesId(dic.keys()), dic.values())) + new_values = tuple( + zip(self.header.getAttributesId(dic.keys()), dic.values()) + ) for i in set(affected.content): i = list(i) - for column,value in new_values: + for column, value in new_values: i[column] = value not_affected.insert(i) @@ -530,6 +533,6 @@ class Header(tuple): '''Returns a list with numeric index corresponding to field's name''' return [self.index(i) for i in param] -#Backwards compatibility +# Backwards compatibility relation = Relation header = Header diff --git a/relational/rtypes.py b/relational/rtypes.py index 82cc72c..a2a61a4 100644 --- a/relational/rtypes.py +++ b/relational/rtypes.py @@ -32,7 +32,9 @@ class Rstring (str): int_regexp = re.compile(r'^[\+\-]{0,1}[0-9]+$') float_regexp = re.compile(r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$') - date_regexp = re.compile(r'^([0-9]{1,4})(\\|-|/)([0-9]{1,2})(\\|-|/)([0-9]{1,2})$') + date_regexp = re.compile( + r'^([0-9]{1,4})(\\|-|/)([0-9]{1,2})(\\|-|/)([0-9]{1,2})$' + ) def autocast(self): ''' @@ -155,11 +157,12 @@ class Rdate (object): def __sub__(self, other): return (self.intdate - other.intdate).days + def is_valid_relation_name(name): '''Checks if a name is valid for a relation. Returns boolean''' return re.match(RELATION_NAME_REGEXP, name) != None -#Backwards compatibility +# Backwards compatibility rdate = Rdate rstring = Rstring diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index 43150d6..d1663a5 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -43,7 +43,7 @@ class relForm(QtWidgets.QMainWindow): # Creates the UI self.ui.setupUi(self) - #Setting fonts for symbols + # Setting fonts for symbols f = QtGui.QFont() size = f.pointSize() if sys.platform.startswith('win'): @@ -106,7 +106,6 @@ class relForm(QtWidgets.QMainWindow): action.setShortcutContext(0) widget.addAction(action) - def checkVersion(self): from relational import maintenance online = maintenance.check_latest_version() @@ -250,8 +249,11 @@ class relForm(QtWidgets.QMainWindow): self, QtWidgets.QApplication.translate("Form", "Error"), r ) return - filename = QtWidgets.QFileDialog.getSaveFileName(self, QtWidgets.QApplication.translate( - "Form", "Save Relation"), "", QtWidgets.QApplication.translate("Form", "Relations (*.csv)"))[0] + filename = QtWidgets.QFileDialog.getSaveFileName( + self, QtWidgets.QApplication.translate("Form", "Save Relation"), + "", + QtWidgets.QApplication.translate("Form", "Relations (*.csv)") + )[0] if (len(filename) == 0): # Returns if no file was selected return self.selectedRelation.save(filename) @@ -366,8 +368,15 @@ class relForm(QtWidgets.QMainWindow): It shouldn't be called giving filename but not giving name.''' # Asking for file to load if not filenames: - f = QtWidgets.QFileDialog.getOpenFileNames(self, QtWidgets.QApplication.translate( - "Form", "Load Relation"), "", QtWidgets.QApplication.translate("Form", "Relations (*.csv);;Text Files (*.txt);;All Files (*)")) + f = QtWidgets.QFileDialog.getOpenFileNames( + self, + QtWidgets.QApplication.translate("Form", "Load Relation"), + "", + QtWidgets.QApplication.translate( + "Form", + "Relations (*.csv);;Text Files (*.txt);;All Files (*)" + ) + ) filenames = f[0] for f in filenames: