Repository: pyccel/pyccel
Pull request #1989 (2024-09-23 14:51:42)

Add a temporary warning for nested list
As mentioned in #1956 nested lists do not yet function correctly. This can be fixed after #1959 but in the meantime a warning is added to discourage the use of this in user code.

EmilyBourne: /bot checklist
pyccel-bot[bot]: Hello again! Thank you for this new pull request :star_struck:.

Please begin by requesting your checklist using the command `/bot checklist`

EmilyBourne: /bot checklist
pyccel-bot[bot]: Unfortunately your PR is not passing the tests so it is not quite ready for review yet. Let me know when it is fixed with `/bot mark as ready`.

pyccel-bot[bot]: Unfortunately your PR is not passing the tests so it is not quite ready for review yet. Let me know when it is fixed with `/bot mark as ready`.

pyccel-bot[bot]: Unfortunately your PR is not passing the tests so it is not quite ready for review yet. Let me know when it is fixed with `/bot mark as ready`.

pyccel-bot[bot]: Hey @pyccel/pyccel-dev ! @EmilyBourne has just created this great new pull request! Check it out and let me know what you think!

pyccel-bot[bot]: Hey @yguclu, @EmilyBourne, this PR is looking pretty good. @EmilyBourne and @jalalium think it is ready to merge. Could you add your expertise to confirm that this follows all the coding conventions and fits in Pyccel's future plans? Thanks :smile:


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a72cb4b2..ddb26cea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,7 @@ All notable changes to this project will be documented in this file.
 -   #1544 : Add support for `typing.TypeAlias`.
 -   #1583 : Allow inhomogeneous tuples in classes.
 -   #1915 : Add support for NumPy v2 `sign` function.
+-   Add a warning about containers in lists.
 -   \[INTERNALS\] Added `container_rank` property to `ast.datatypes.PyccelType` objects.
 -   \[DEVELOPER\] Added an improved traceback to the developer-mode errors for errors in function calls.
 
diff --git a/pyccel/ast/datatypes.py b/pyccel/ast/datatypes.py
index c69516ab..3105ebcd 100644
--- a/pyccel/ast/datatypes.py
+++ b/pyccel/ast/datatypes.py
@@ -12,9 +12,12 @@ from functools import lru_cache
 
 import numpy
 
+from pyccel.errors.errors     import Errors
 from pyccel.utilities.metaclasses import Singleton, ArgumentSingleton
 from .basic import iterable
 
+errors = Errors()
+
 __all__ = (
         # ------------ Super classes ------------
         'PyccelType',
@@ -785,6 +788,8 @@ class HomogeneousListType(HomogeneousContainerType, metaclass = ArgumentSingleto
 
     def __init__(self, element_type):
         assert isinstance(element_type, PyccelType)
+        if element_type.rank > 0:
+            errors.report("Nested lists are not yet fully supported. Using containers in lists may lead to bugs such as memory leaks", symbol=self, severity="warning")
         self._element_type = element_type
         self._order = 'C' if (element_type.order == 'C' or element_type.rank == 1) else None
         super().__init__()


Test patch:
diff --git a/tests/warnings/semantic/NESTED_LISTS.py b/tests/warnings/semantic/NESTED_LISTS.py
new file mode 100644
index 00000000..cbda5875
--- /dev/null
+++ b/tests/warnings/semantic/NESTED_LISTS.py
@@ -0,0 +1,4 @@
+# pylint: disable=missing-module-docstring
+
+if __name__ == '__main__':
+    a = [[1,2], [3,4]]
diff --git a/tests/warnings/test_warnings.py b/tests/warnings/test_warnings.py
index fd0b6e43..b43d1cee 100644
--- a/tests/warnings/test_warnings.py
+++ b/tests/warnings/test_warnings.py
@@ -37,6 +37,7 @@ def get_files_from_folder(foldername):
 #
 #    assert errors.num_messages()!=0
 
+@pytest.mark.xdist_incompatible
 @pytest.mark.parametrize("f",get_files_from_folder('semantic'))
 def test_semantic_warnings(f):