Use fstrings
This commit is contained in:
parent
ef28b7272e
commit
ccfdff6fd3
@ -134,7 +134,7 @@ class Relation(NamedTuple):
|
|||||||
try:
|
try:
|
||||||
c_expr = compile(expr, 'selection', 'eval')
|
c_expr = compile(expr, 'selection', 'eval')
|
||||||
except:
|
except:
|
||||||
raise Exception('Failed to compile expression: %s' % expr)
|
raise Exception(f'Failed to compile expression: {expr}')
|
||||||
|
|
||||||
content = []
|
content = []
|
||||||
for i in self.content:
|
for i in self.content:
|
||||||
@ -147,8 +147,7 @@ class Relation(NamedTuple):
|
|||||||
if eval(c_expr, attributes):
|
if eval(c_expr, attributes):
|
||||||
content.append(i)
|
content.append(i)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(
|
raise Exception(f'Failed to evaluate {expr}\n{e}')
|
||||||
"Failed to evaluate %s\n%s" % (expr, e.__str__()))
|
|
||||||
return Relation(header, frozenset(content))
|
return Relation(header, frozenset(content))
|
||||||
|
|
||||||
def product(self, other: 'Relation') -> 'Relation':
|
def product(self, other: 'Relation') -> 'Relation':
|
||||||
@ -403,7 +402,7 @@ class Header(tuple):
|
|||||||
|
|
||||||
for i in self:
|
for i in self:
|
||||||
if not is_valid_relation_name(i):
|
if not is_valid_relation_name(i):
|
||||||
raise Exception('"%s" is not a valid attribute name' % i)
|
raise Exception(f'"{i}" is not a valid attribute name')
|
||||||
|
|
||||||
if len(self) != len(set(self)):
|
if len(self) != len(set(self)):
|
||||||
raise Exception('Attribute names must be unique')
|
raise Exception('Attribute names must be unique')
|
||||||
@ -419,12 +418,12 @@ class Header(tuple):
|
|||||||
attrs = list(self)
|
attrs = list(self)
|
||||||
for old, new in params.items():
|
for old, new in params.items():
|
||||||
if not is_valid_relation_name(new):
|
if not is_valid_relation_name(new):
|
||||||
raise Exception('%s is not a valid attribute name' % new)
|
raise Exception(f'{new} is not a valid attribute name')
|
||||||
try:
|
try:
|
||||||
id_ = attrs.index(old)
|
id_ = attrs.index(old)
|
||||||
attrs[id_] = new
|
attrs[id_] = new
|
||||||
except:
|
except:
|
||||||
raise Exception('Field not found: %s' % old)
|
raise Exception(f'Field not found: {old}')
|
||||||
return Header(attrs)
|
return Header(attrs)
|
||||||
|
|
||||||
def sharedAttributes(self, other: 'Header') -> int:
|
def sharedAttributes(self, other: 'Header') -> int:
|
||||||
|
Loading…
Reference in New Issue
Block a user