|
8 | 8 | """
|
9 | 9 |
|
10 | 10 | from itertools import chain, product
|
| 11 | +import os |
11 | 12 | import warnings
|
12 | 13 |
|
13 | 14 | from sympy.utilities.iterables import iterable as sympy_iterable
|
|
57 | 58 | from pyccel.ast.core import Decorator
|
58 | 59 | from pyccel.ast.core import PyccelFunctionDef
|
59 | 60 | from pyccel.ast.core import Assert
|
| 61 | +from pyccel.ast.core import AllDeclaration |
60 | 62 |
|
61 | 63 | from pyccel.ast.class_defs import get_cls_base
|
62 | 64 |
|
@@ -1610,8 +1612,10 @@ def _assign_lhs_variable(self, lhs, d_var, rhs, new_expressions, is_augassign =
|
1610 | 1612 |
|
1611 | 1613 | # Not yet supported for arrays: x=y+z, x=b[:]
|
1612 | 1614 | # Because we cannot infer shape of right-hand side yet
|
1613 |
| - know_lhs_shape = (lhs.rank == 0) or all(sh is not None for sh in lhs.alloc_shape) \ |
1614 |
| - or isinstance(lhs.class_type, StringType) |
| 1615 | + if isinstance(lhs.dtype, StringType): |
| 1616 | + know_lhs_shape = (lhs.rank == 1) or all(sh is not None for sh in lhs.alloc_shape[:-1]) |
| 1617 | + else: |
| 1618 | + know_lhs_shape = (lhs.rank == 0) or all(sh is not None for sh in lhs.alloc_shape) |
1615 | 1619 |
|
1616 | 1620 | if isinstance(class_type, (NumpyNDArrayType, HomogeneousTupleType)) and not know_lhs_shape:
|
1617 | 1621 | msg = f"Cannot infer shape of right-hand side for expression {lhs} = {rhs}"
|
@@ -3590,6 +3594,21 @@ def _visit_Assign(self, expr):
|
3590 | 3594 |
|
3591 | 3595 | new_expressions.append(new_expr)
|
3592 | 3596 |
|
| 3597 | + if expr.lhs == '__all__': |
| 3598 | + self.scope.remove_variable(lhs[0]) |
| 3599 | + self._allocs[-1].discard(lhs[0]) |
| 3600 | + if isinstance(lhs[0].class_type, HomogeneousListType): |
| 3601 | + # Remove the last element of the errors (if it is a warning) |
| 3602 | + # This will be the list of list warning |
| 3603 | + try: |
| 3604 | + error_info_map = errors.error_info_map[os.path.basename(errors.target)] |
| 3605 | + if error_info_map[-1].severity == 'warning': |
| 3606 | + error_info_map.pop() |
| 3607 | + except KeyError: |
| 3608 | + # There may be a KeyError if this is not the first time that this DataType |
| 3609 | + # of list of rank>0 is created. |
| 3610 | + pass |
| 3611 | + return AllDeclaration(new_expressions[-1].rhs) |
3593 | 3612 |
|
3594 | 3613 | if (len(new_expressions)==1):
|
3595 | 3614 | new_expressions = new_expressions[0]
|
|
0 commit comments