@@ -127,7 +127,7 @@ def new_child_scope(self, name, **kwargs):
127
127
"""
128
128
ps = kwargs .pop ('parent_scope' , self )
129
129
if ps is not self :
130
- raise ValueError ("A child of {} cannot have a parent {}" . format ( self , ps ) )
130
+ raise ValueError (f "A child of { self } cannot have a parent { ps } " )
131
131
132
132
child = Scope (name = name , ** kwargs , parent_scope = self )
133
133
@@ -308,21 +308,17 @@ def create_new_loop_scope(self):
308
308
return new_scope
309
309
310
310
def insert_variable (self , var , name = None ):
311
- """ Add a variable to the current scope
311
+ """
312
+ Add a variable to the current scope.
313
+
314
+ Add a variable to the current scope.
312
315
313
316
Parameters
314
317
----------
315
- var : Variable
316
- The variable to be inserted into the current scope
317
- name : str
318
- The name of the variable in the python code
319
- Default : var.name
320
- python_scope : bool
321
- If true then we assume that python scoping applies.
322
- In this case variables declared in loops exist beyond
323
- the end of the loop. Otherwise variables may be local
324
- to loops
325
- Default : True
318
+ var : Variable
319
+ The variable to be inserted into the current scope.
320
+ name : str, default=var.name
321
+ The name of the variable in the Python code.
326
322
"""
327
323
if var .name == '_' :
328
324
raise ValueError ("A temporary variable should have a name generated by Scope.get_new_name" )
@@ -336,7 +332,7 @@ def insert_variable(self, var, name = None):
336
332
self .parent_scope .insert_variable (var , name )
337
333
else :
338
334
if name in self ._locals ['variables' ]:
339
- raise RuntimeError ('New variable {} already exists in scope' . format ( name ) )
335
+ raise RuntimeError (f 'New variable { name } already exists in scope' )
340
336
if name == '_' :
341
337
self ._temporary_variables .append (var )
342
338
else :
@@ -645,17 +641,24 @@ def get_new_name(self, current_name = None):
645
641
646
642
def get_temporary_variable (self , dtype_or_var , name = None , ** kwargs ):
647
643
"""
648
- Get a temporary variable
644
+ Get a temporary variable.
645
+
646
+ Get a temporary variable.
649
647
650
648
Parameters
651
649
----------
652
650
dtype_or_var : str, DataType, Variable
653
651
In the case of a string of DataType: The type of the Variable to be created
654
- In the case of a Variable: a Variable which will be cloned to set all the Variable properties
655
- name : str
656
- The requested name for the new variable
657
- kwargs : dict
658
- See Variable keyword arguments
652
+ In the case of a Variable: a Variable which will be cloned to set all the Variable properties.
653
+ name : str, optional
654
+ The requested name for the new variable.
655
+ **kwargs : dict
656
+ See Variable keyword arguments.
657
+
658
+ Returns
659
+ -------
660
+ Variable
661
+ The temporary variable.
659
662
"""
660
663
assert isinstance (name , (str , type (None )))
661
664
name = self .get_new_name (name )
@@ -667,8 +670,21 @@ def get_temporary_variable(self, dtype_or_var, name = None, **kwargs):
667
670
return var
668
671
669
672
def get_expected_name (self , start_name ):
670
- """ Get a name with no collisions, ideally the provided name.
671
- The provided name should already exist in the symbols
673
+ """
674
+ Get a name with no collisions.
675
+
676
+ Get a name with no collisions, ideally the provided name.
677
+ The provided name should already exist in the symbols.
678
+
679
+ Parameters
680
+ ----------
681
+ start_name : str
682
+ The name which was used in the Python code.
683
+
684
+ Returns
685
+ -------
686
+ PyccelSymbol
687
+ The name which will be used in the generated code.
672
688
"""
673
689
if start_name == '_' :
674
690
return self .get_new_name ()
@@ -677,7 +693,7 @@ def get_expected_name(self, start_name):
677
693
elif self .parent_scope :
678
694
return self .parent_scope .get_expected_name (start_name )
679
695
else :
680
- raise RuntimeError ("{ } does not exist in scope". format ( start_name ) )
696
+ raise RuntimeError (f" { start_name } does not exist in scope" )
681
697
682
698
def create_product_loop_scope (self , inner_scope , n_loops ):
683
699
""" Create a n_loops loop scopes such that the innermost loop
@@ -749,15 +765,28 @@ def add_son(self, name, son):
749
765
self ._sons_scopes [name ] = son
750
766
751
767
def get_python_name (self , name ):
752
- """ Get the name used in the original python code from the
753
- name used by the variable
768
+ """
769
+ Get the name used in the original Python code.
770
+
771
+ Get the name used in the original Python code from the name used
772
+ by the variable that was created in the parser.
773
+
774
+ Parameters
775
+ ----------
776
+ name : PyccelSymbol | str
777
+ The name of the Variable in the generated code.
778
+
779
+ Returns
780
+ -------
781
+ str
782
+ The name of the Variable in the original code.
754
783
"""
755
784
if name in self ._original_symbol :
756
785
return self ._original_symbol [name ]
757
786
elif self .parent_scope :
758
787
return self .parent_scope .get_python_name (name )
759
788
else :
760
- raise RuntimeError ("Can't find {} in scope" . format ( name ) )
789
+ raise RuntimeError (f "Can't find { name } in scope" )
761
790
762
791
@property
763
792
def python_names (self ):
0 commit comments