Skip to content

Commit

Permalink
[PYLINT] consider-using-f-string
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyBourne committed Jul 18, 2023
1 parent 89dc06b commit ce1186d
Show file tree
Hide file tree
Showing 30 changed files with 430 additions and 472 deletions.
4 changes: 2 additions & 2 deletions pyccel/ast/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self):
setattr(self, c_name, c)

elif not isinstance(c, Basic):
raise TypeError("Basic child must be a Basic or a tuple not {}".format(type(c)))
raise TypeError(f"Basic child must be a Basic or a tuple not {type(c)}")


if isinstance(c, tuple):
Expand Down Expand Up @@ -310,7 +310,7 @@ def is_atomic(self):
def set_fst(self, fst):
"""Sets the python.ast fst."""
if not isinstance(fst, ast.AST):
raise TypeError("Fst must be an AST object, not {}".format(type(fst)))
raise TypeError(f"Fst must be an AST object, not {type(fst)}")

if self.fst:
if hasattr(fst, 'lineno'):
Expand Down
18 changes: 9 additions & 9 deletions pyccel/ast/bitwise_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def _calculate_dtype(self, *args):
dtype = NativeInteger()
a = args[0]
if a.dtype not in (NativeInteger(), NativeBool()):
raise TypeError('unsupported operand type(s): {}'.format(args))
raise TypeError(f'unsupported operand type(s): {args}')

self._args = (PythonInt(a) if a.dtype is NativeBool() else a,)
precision = a.precision
return dtype, precision

def __repr__(self):
return '~{}'.format(repr(self.args[0]))
return f'~{repr(self.args[0])}'

#==============================================================================

Expand Down Expand Up @@ -93,11 +93,11 @@ def _calculate_dtype(self, *args):
strs = [a for a in args if a.dtype is NativeString()]

if strs or complexes or floats:
raise TypeError('unsupported operand type(s): {}'.format(args))
raise TypeError(f'unsupported operand type(s): {args}')
elif integers:
return self._handle_integer_type(integers)
else:
raise TypeError('cannot determine the type of {}'.format(args))
raise TypeError(f'cannot determine the type of {args}')

def _set_shape_rank(self):
pass
Expand Down Expand Up @@ -135,7 +135,7 @@ class PyccelRShift(PyccelBitOperator):
_precedence = 11

def __repr__(self):
return '{} >> {}'.format(self.args[0], self.args[1])
return f'{self.args[0]} >> {self.args[1]}'

#==============================================================================

Expand All @@ -158,7 +158,7 @@ class PyccelLShift(PyccelBitOperator):
_precedence = 11

def __repr__(self):
return '{} << {}'.format(self.args[0], self.args[1])
return f'{self.args[0]} << {self.args[1]}'

#==============================================================================

Expand Down Expand Up @@ -206,7 +206,7 @@ class PyccelBitXor(PyccelBitComparisonOperator):
_precedence = 9

def __repr__(self):
return '{} ^ {}'.format(self.args[0], self.args[1])
return f'{self.args[0]} ^ {self.args[1]}'

#==============================================================================

Expand All @@ -229,7 +229,7 @@ class PyccelBitOr(PyccelBitComparisonOperator):
_precedence = 8

def __repr__(self):
return '{} | {}'.format(self.args[0], self.args[1])
return f'{self.args[0]} | {self.args[1]}'

#==============================================================================

Expand All @@ -252,4 +252,4 @@ class PyccelBitAnd(PyccelBitComparisonOperator):
_precedence = 10

def __repr__(self):
return '{} & {}'.format(self.args[0], self.args[1])
return f'{self.args[0]} & {self.args[1]}'
43 changes: 22 additions & 21 deletions pyccel/ast/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __new__(cls, arg):
return super().__new__(cls)

def __str__(self):
return 'Real({0})'.format(str(self.internal_var))
return f'Real({self.internal_var})'

#==============================================================================
class PythonImag(PythonComplexProperty):
Expand All @@ -123,7 +123,7 @@ def __new__(cls, arg):
return super().__new__(cls)

def __str__(self):
return 'Imag({0})'.format(str(self.internal_var))
return f'Imag({self.internal_var})'

#==============================================================================
class PythonConjugate(PyccelInternalFunction):
Expand Down Expand Up @@ -169,7 +169,7 @@ def internal_var(self):
return self._args[0]

def __str__(self):
return 'Conjugate({0})'.format(str(self.internal_var))
return f'Conjugate({self.internal_var})'

#==============================================================================
class PythonBool(PyccelAstNode):
Expand Down Expand Up @@ -201,7 +201,7 @@ def arg(self):
return self._arg

def __str__(self):
return 'Bool({})'.format(str(self.arg))
return f'Bool({self.arg})'

#==============================================================================
class PythonComplex(PyccelAstNode):
Expand Down Expand Up @@ -303,7 +303,7 @@ def internal_var(self):
return self._internal_var

def __str__(self):
return "complex({}, {})".format(str(self.real), str(self.imag))
return f"complex({self.real}, {self.imag})"

#==============================================================================
class PythonEnumerate(Basic):
Expand Down Expand Up @@ -373,7 +373,7 @@ def arg(self):
return self._arg

def __str__(self):
return 'float({0})'.format(str(self.arg))
return f'float({self.arg})'

#==============================================================================
class PythonInt(PyccelAstNode):
Expand Down Expand Up @@ -458,7 +458,7 @@ def __init__(self, *args):
self._dtype = NativeBool()
self._precision = max_precision(bools)
else:
raise TypeError('cannot determine the type of {}'.format(self))
raise TypeError(f'cannot determine the type of {self}')


inner_shape = [() if a.rank == 0 else a.shape for a in args]
Expand Down Expand Up @@ -499,7 +499,7 @@ def to_int(a):
elif self.is_homogeneous:
return IndexedElement(self, i)
else:
raise NotImplementedError("Can't index PythonTuple with type {}".format(type(i)))
raise NotImplementedError(f"Can't index PythonTuple with type {type(i)}")

def __add__(self,other):
return PythonTuple(*(self._args + other._args))
Expand All @@ -511,10 +511,12 @@ def __len__(self):
return len(self._args)

def __str__(self):
return '({})'.format(', '.join(str(a) for a in self))
args = ', '.join(str(a) for a in self)
return f'({args})'

def __repr__(self):
return 'PythonTuple({})'.format(', '.join(str(a) for a in self))
args = ', '.join(str(a) for a in self)
return f'PythonTuple({args})'

@property
def is_homogeneous(self):
Expand Down Expand Up @@ -560,7 +562,7 @@ def arg(self):
return self._args[0]

def __str__(self):
return 'len({})'.format(str(self.arg))
return f'len({self.arg})'

#==============================================================================
class PythonList(PythonTuple):
Expand Down Expand Up @@ -766,7 +768,7 @@ class PythonSum(PyccelInternalFunction):

def __init__(self, arg):
if not isinstance(arg, PyccelAstNode):
raise TypeError('Unknown type of %s.' % type(arg))
raise TypeError(f'Unknown type of {type(arg)}.' )
self._dtype = arg.dtype
self._precision = -1
super().__init__(arg)
Expand Down Expand Up @@ -794,11 +796,11 @@ def __init__(self, *x):
if isinstance(x, (list, tuple)):
x = PythonTuple(*x)
elif not isinstance(x, (PythonTuple, PythonList)):
raise TypeError('Unknown type of %s.' % type(x))
raise TypeError(f'Unknown type of {type(x)}.' )
if not x.is_homogeneous:
types = ', '.join('{}({})'.format(xi.dtype,xi.precision) for xi in x)
types = ', '.join('{xi.dtype}({xi.precision})' for xi in x)
raise PyccelError("Cannot determine final dtype of 'max' call with arguments of different "
"types ({}). Please cast arguments to the desired dtype".format(types))
f"types ({types}). Please cast arguments to the desired dtype")
self._dtype = x.dtype
self._precision = x.precision
super().__init__(x)
Expand All @@ -822,11 +824,11 @@ def __init__(self, *x):
if isinstance(x, (list, tuple)):
x = PythonTuple(*x)
elif not isinstance(x, (PythonTuple, PythonList)):
raise TypeError('Unknown type of %s.' % type(x))
raise TypeError(f'Unknown type of {type(x)}.' )
if not x.is_homogeneous:
types = ', '.join('{}({})'.format(xi.dtype,xi.precision) for xi in x)
types = ', '.join(f'{xi.dtype}({xi.precision})' for xi in x)
raise PyccelError("Cannot determine final dtype of 'min' call with arguments of different "
"types ({}). Please cast arguments to the desired dtype".format(types))
f"types ({types}). Please cast arguments to the desired dtype")
self._dtype = x.dtype
self._precision = x.precision
super().__init__(x)
Expand Down Expand Up @@ -871,8 +873,7 @@ def __call__(self, *args):
return self.expr.subs(self.variables, args)

def __str__(self):
return "{args} -> {expr}".format(args=self.variables,
expr = self.expr)
return f"{self.variables} -> {self.expr}"

#==============================================================================
class PythonType(Basic):
Expand All @@ -896,7 +897,7 @@ class PythonType(Basic):

def __init__(self, obj):
if not isinstance (obj, PyccelAstNode):
raise PyccelError("Python's type function is not implemented for {} object".format(type(obj)))
raise PyccelError(f"Python's type function is not implemented for {type(obj)} object")
self._dtype = obj.dtype
self._precision = obj.precision
self._obj = obj
Expand Down

0 comments on commit ce1186d

Please sign in to comment.